Sf: vars argument for plot_sf

Created on 14 Oct 2017  Â·  8Comments  Â·  Source: r-spatial/sf

Related to #457. I appreciate one should do plot(sf_object$geometry, ...), but I think the geometry column is an implementation detail, and many users will just hope to do plot(sf_object) and select the variable(s) they want to plot. So, could I suggest an argument to the plot function that selects one or more variables to plot? If you're agreeable to this, I could try to provide a pull request.

Most helpful comment

The "logic", if you wish, of this behaviour is that plot(x) gives you a plot of x, i.e. its entirety. I believe that many people make different assumptions because in sp, plot(x) was synonymous to plot(geometry(x)), and this has been so for over a decade. The disadvantage of that was that for every quick plot, you'd have to start messing with classifying a column and mapping it to colors. Think of what you see with you plot(mtcars): it's not good, but does plot all variables, and pairs.

I agree that in case of many attributes the default of plotting the first 10 is rather arbitrary (but similar to what tibbles do). We could manipulate this by creating a global option (e.g., options("sf.plot_ncol")). I'm not a fan of global options, but would consider a PR doing (and documenting) this in a clean way (see e.g. file AAA.R in package sp).

I don't agree that for and sf object with attributes, plot(x) and plot(st_geometry(x)) should do the same thing.

All 8 comments

Correct me if I'm wrong, but you can do that right now by plot(sf_object["var_name"]).

I guess that is true. It is perhaps not very easy to discover, though.
Intuitively, that looks like plotting a single vector.

David

On 14 October 2017 at 19:08, Jakub Nowosad notifications@github.com wrote:

Correct me if I'm wrong, but you can do that right now by
plot(sf_object["var_name"]).

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/r-spatial/sf/issues/516#issuecomment-336653080, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AFjJ98akMLwYfPp8CPnFUbDg5sj43sGWks5ssPi2gaJpZM4P5d3l
.

On a similar note I find that I often end up just writing plot(sf_object) and then, if my sf object has many columns, I start waiting for all the first 10 columns to be plotted one alongside the other (or have to kill the process because it takes too long depending on the input).

I would too vouch for a "default" behaviour which just plots the geometry, or maybe just the first "column" of the object. If I read the documentation correctly, implementing the second option would just mean to change the default value for max.plot (currently, set to 9).

The "logic", if you wish, of this behaviour is that plot(x) gives you a plot of x, i.e. its entirety. I believe that many people make different assumptions because in sp, plot(x) was synonymous to plot(geometry(x)), and this has been so for over a decade. The disadvantage of that was that for every quick plot, you'd have to start messing with classifying a column and mapping it to colors. Think of what you see with you plot(mtcars): it's not good, but does plot all variables, and pairs.

I agree that in case of many attributes the default of plotting the first 10 is rather arbitrary (but similar to what tibbles do). We could manipulate this by creating a global option (e.g., options("sf.plot_ncol")). I'm not a fan of global options, but would consider a PR doing (and documenting) this in a clean way (see e.g. file AAA.R in package sp).

I don't agree that for and sf object with attributes, plot(x) and plot(st_geometry(x)) should do the same thing.

Maybe just reducing the default would be reasonable. I had the same problem
as Lorenzo of waiting for very large objects to plot.

David

On 15 October 2017 at 14:26, Edzer Pebesma notifications@github.com wrote:

The "logic", if you wish, of this behaviour is that plot(x) gives you a
plot of x, i.e. its entirety. I believe that many people make different
assumptions because in sp, plot(x) was synonymous to plot(geometry(x)),
and this has been so for over a decade. The disadvantage of that was that
for every quick plot, you'd have to start messing with classifying a column
and mapping it to colors. Think of what you see with you plot(mtcars):
it's not good, but does plot all variables, and pairs.

I agree that in case of many attributes the default of plotting the first
10 is rather arbitrary (but similar to what tibbles do). We could
manipulate this by creating a global option (e.g., options("sf.plot_ncol")).
I'm not a fan of global options, but would consider a PR doing (and
documenting) this in a clean way (see e.g. file AAA.R in package sp).

I don't agree that for and sf object with attributes, plot(x) and
plot(st_geometry(x)) should do the same thing.

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/r-spatial/sf/issues/516#issuecomment-336711493, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AFjJ99bBzZSDioNtWfJEO0g6VTEy3_myks5ssggPgaJpZM4P5d3l
.

On most platforms, plot can be easily interrupted without disturbing your R session. A single map can also be so large that you have to wait for it to plot. And when you're ready to use geom_sf in ggplot2, you'll have to redefine what you meant by "waiting". I think it'll be tough to make everyone happy, here.

I think the "global option" idea could be a good "compromise" (and could maybe useful also for customizing other options users may wish to customize in the future). I'll see if I can manage to do a PR in the next days.

I find using select() very effective:

library(sf)
library(tidyverse)

nc = st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE)

nc %>% 
    select(AREA, NAME) %>% 
    plot()
Was this page helpful?
0 / 5 - 0 ratings

Related issues

kendonB picture kendonB  Â·  3Comments

ekarsten picture ekarsten  Â·  4Comments

angela-li picture angela-li  Â·  4Comments

dpprdan picture dpprdan  Â·  4Comments

kendonB picture kendonB  Â·  4Comments