Skip to content
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

vars argument for plot_sf #516

Closed
hughjonesd opened this issue Oct 14, 2017 · 8 comments
Closed

vars argument for plot_sf #516

hughjonesd opened this issue Oct 14, 2017 · 8 comments

Comments

@hughjonesd
Copy link
Contributor

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.

@Nowosad
Copy link
Contributor

Nowosad commented Oct 14, 2017

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

@hughjonesd
Copy link
Contributor Author

hughjonesd commented Oct 14, 2017 via email

@lbusett
Copy link
Contributor

lbusett commented Oct 14, 2017

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).

@edzer
Copy link
Member

edzer commented Oct 15, 2017

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.

@hughjonesd
Copy link
Contributor Author

hughjonesd commented Oct 15, 2017 via email

@edzer
Copy link
Member

edzer commented Oct 15, 2017

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.

@lbusett
Copy link
Contributor

lbusett commented Oct 15, 2017

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.

@etiennebr
Copy link
Member

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()

@edzer edzer closed this as completed in 78c04ac Oct 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants