-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tm_labels -> looking for algorithms #850
Comments
This all looks good to me. I remember seeing a very good package for generating labels along curved lines but cannot recall what it's called. The {ggrepel} also provides good non-overlapping labels. Could that be useful for |
Maybe also useful for polygons |
I used |
Thanks for your input! @Robinlovelace Yes, indeed, but see the last paragraph of my opening post. |
Hi @mtennekes ! I used a combination of automatic optimization of y coordinate and manual placement in x direction. I updated my code to use sf and changed it to take the borders into account.
|
I was reminded of isoband, but I'm not sure how good the algo is. Placement is pretty nice: |
In tmap4, I started the implementation of 2 text layer functions:
tm_text
Intended to print text to represent data directly, i.e. with visual variables.tm_labels
To label points, lines, and/or polygons.The coordinates in
tm_text
are as the are (by default). Example:For
tm_labels
the aim is not to print the text at the exact coordinates, but next to (or on top of) the geometries that they refer to.So, this function requires some intelligent algorithms to place the text.
tmap3 already contained some 'intelligent' features in
tm_text
, namely the argumentsauto.placement
,remove.overlap
,along.lines
andoverwrite.lines
. I've migrated all of them in tmap4 already (except the last one, which was also not working well in the latest version of tmap3). But there still is a need for further extensions.Points:
The automatic placement function for points is based on
car::pointLabel
(earlier part of maptools). This function was also used in tmap3, but I improved it a bit. What is does: it places the labels are close to (but not on top of) the points such that overlap is minimised. Under the hood, simulated annealing and a generic algorithm are used:The automatic removal of overlapping labels is also implemented, but could be improved. For instance, we should be able to specify some sort of weight, determining the importance of the labels.
What we also need: linking lines between labels and points, especially for those that are far away.
Lines
For labeling lines, the option
along.lines
has been migrated from tmap3. This calculates the angle of the line at the centroid. It works okayish, but needs refinement. Ideally, the labels should be right next to the lines rather than on top:Polygons
No implementation yet. In tmap3, the user could scale the text with
"AREA"
, and use several scaling settings withroot
,print.tiny
, andsize.lowerbound
. In tmap4, those belong imho totm_text
and the visual variablesize
. Fortm_labels
I am looking for a geometry-driven rather data-driven procedure.What I have in mind is the following configurable procedure like this:
stay.at.centroid
to prevent that text labels are drawn elsewhere,allow.rotation
to allow labels to be rotated if they have a better fit (think of Italy).decrease.font.size
to decrease font size in case labels do not fit.Options
Note:
tm_text
andtm_labels
are the same layer function, but with different layer options. As you can see, I've placed them intoopt_tm_<layer>
, (see #848 option4).The option names are not finalised, so if you have suggestions for better option names, let me know!
Tips and help welcome!
Do you know any implemented algorithms and we can use? There is
ggrepel
(mentioned in #808), but so far, I wasn't able to extract the algorithms from the ggplot2 ecosystem. Help is more than welcome.Also related to #279 and #373, and pinging @Nowosad @Robinlovelace @olivroy @agila5 @rogerbeecham @staropram
The text was updated successfully, but these errors were encountered: