tmap icon indicating copy to clipboard operation
tmap copied to clipboard

Additional charts (e.g. histograms and marginal rugs)

Open sriramab opened this issue 4 years ago • 4 comments

Greetings.

Is it possible to have a geom_rug style "on axis" ticks for point features? If not, I would like to request for such a feature as it helps visualizing density of point features along x and y. And some alpha color/transparency correction for potential dense layers.

Thank you.

sriramab avatar Jul 18 '21 16:07 sriramab

Working on the next big hurdle for tmap4: histograms and other charts.

tmap3 only supported histograms for discrete color legends, so quite limiting.

My initial idea for tmap4 (see https://github.com/r-tmap/tmap/issues/725#issuecomment-1512547136) was to have a .chart argument for each visual variable:

tm_shape(World) +
  tm_polygons(
    fill = "economy", 
    fill.chart = tm_chart_histogram(position = c("left", "bottom"))

However, this is also limiting in the sense that only univariate plots can be generated. It would also be great to be able to create bi/multivariate plots, e.g. a scatter plot using two visual variables. Possible solution:

tm_shape(World) +
  tm_polygons(
    fill = "economy", 
    lwd = "HPI",
    charts = list(tm_chart_histogram("economy"), tm_chart_scatter("economy", "HPI"))

This is quite a lot of work, but on the other hand, the current v3 implementation is not very useful (and still some work to migrate).

Another option is to use ggplot2:

tm_shape(World) +
  tm_polygons(
    fill = "economy", 
    lwd = "HPI",
    charts = list(ggplot(., aes(x = economy, y = HPI)) + geom_boxplot()))

Downsides:

  • Extra dependencies
  • Visual values are not automatically passed on to the chart elements (e.g polygon colors to the bars of a histogram).

So I'm leaning towards the first option. Perhaps just start with a very ugly implementation of tm_chart_histogram, and after that a tm_chart_scatter, just to get it working as POC.

What are your thoughts, @Nowosad @Robinlovelace @olivroy @sriramab ?

mtennekes avatar Sep 28 '23 16:09 mtennekes

Adding ggplot2 graph capabilities would be amazing, and not big deal if it were added as Suggests.

Robinlovelace avatar Sep 28 '23 19:09 Robinlovelace

@mtennekes I think that it is better to start small (with option 1) and then expand.

Regarding option 3 (if still tried): would it not be better if there is an option of just adding a grob-a-like object (e.g., ggplot2) to this argument?

Nowosad avatar Oct 02 '23 20:10 Nowosad

Started a new branch "charts".

The approach is the original option (1), but charts are generated with ggplot2 under the hood. (To make life easy for me:-)). Chart functions such as tm_chart_histogram will get some arguments to tweak. First idea:

Screenshot 2023-10-08 at 18 44 56 Screenshot 2023-10-08 at 18 45 10

Besides that, I'm thinking about a general function tm_container where users can specify their own ggplot2 function (or grob object). The only thing that it does, is place that nearly under/next to the other components/legends.

mtennekes avatar Oct 08 '23 16:10 mtennekes