-
Notifications
You must be signed in to change notification settings - Fork 3
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
Create a map with a legend (categorical legend) in R #3
Comments
Hello : ) This is set to be the second map in the Vis: Section 1. From: Leah Wasser [mailto:[email protected]] Hey @bbesthttps://github.com/bbest @megwilliamshttps://github.com/megwilliams @kwiterhttps://github.com/kwiter -- did any of you work on creating a map (or have you done this) where you have a shapefile (eg the roads_streams lines shapefile in our data ), and you create a map with the lines colored by category. IN essence "TYPE" or an attribute becomes a factor. We have the following below which seems a bit cumbersome but works. We are using the roads_streams shapefile. I am not sure how to add a legend or to make a nice categorical plot. Is there a simple way to do and teach this? Thanks for any ideas! #color lines by TYPE attribute type <- slot(object = lines, name = "data")$TYPE #you can also write type <- lines@data$TYPE col <- rep(x= "black", length = length(type)) col[type == "footpath"] <- "red" plot(x=lines, col=col,add=T) — |
Thank you Meg! Let me know if i can be helpful in any way :) LeahLeah A. Wasser, Ph.D. Boulder, ColoradoFor free tutorials and resources on working with spatio-temporal data: From: megwilliams <[email protected]mailto:[email protected]> Hello : ) This is set to be the second map in the Vis: Section 1. From: Leah Wasser [mailto:[email protected]] Hey @bbesthttps://github.com/bbest @megwilliamshttps://github.com/megwilliams @kwiterhttps://github.com/kwiter -- did any of you work on creating a map (or have you done this) where you have a shapefile (eg the roads_streams lines shapefile in our data ), and you create a map with the lines colored by category. IN essence "TYPE" or an attribute becomes a factor. We have the following below which seems a bit cumbersome but works. We are using the roads_streams shapefile. I am not sure how to add a legend or to make a nice categorical plot. Is there a simple way to do and teach this? Thanks for any ideas! #color lines by TYPE attribute type <- slot(object = lines, name = "data")$TYPE #you can also write type <- lines@data$TYPE col <- rep(x= "black", length = length(type)) col[type == "footpath"] <- "red" plot(x=lines, col=col,add=T) Reply to this email directly or view it on GitHubhttps://github.com//issues/3. Reply to this email directly or view it on GitHubhttps://github.com//issues/3#issuecomment-151547856. |
We were debating ggplot vs base R. I had started with ggplot (very easy for polys), then thought about converting code to base to make it easier to incorporate rasters later. If you have a preference for the overall lesson, I’m very happy go that way. From: Leah Wasser [mailto:[email protected]] Thank you Meg! Let me know if i can be helpful in any way :) LeahLeah A. Wasser, Ph.D. Boulder, ColoradoFor free tutorials and resources on working with spatio-temporal data: From: megwilliams <[email protected]<mailto:[email protected]mailto:[email protected]%3cmailto:[email protected]>> Hello : ) This is set to be the second map in the Vis: Section 1. From: Leah Wasser [mailto:[email protected]] Hey @bbesthttps://github.com/bbest @megwilliamshttps://github.com/megwilliams @kwiterhttps://github.com/kwiter -- did any of you work on creating a map (or have you done this) where you have a shapefile (eg the roads_streams lines shapefile in our data ), and you create a map with the lines colored by category. IN essence "TYPE" or an attribute becomes a factor. We have the following below which seems a bit cumbersome but works. We are using the roads_streams shapefile. I am not sure how to add a legend or to make a nice categorical plot. Is there a simple way to do and teach this? Thanks for any ideas! #color lines by TYPE attribute type <- slot(object = lines, name = "data")$TYPE #you can also write type <- lines@data$TYPE col <- rep(x= "black", length = length(type)) col[type == "footpath"] <- "red" plot(x=lines, col=col,add=T) Reply to this email directly or view it on GitHubhttps://github.com//issues/3. Reply to this email directly or view it on GitHubhttps://github.com//issues/3#issuecomment-151547856. — |
Good discussion here @megwilliams and @lwasser! I like the possibility of someday showing this vector plotting functionality for both base and ggplot2 packages. I'm gonna mostly be offline the next week but look forward to revisiting this later with y'all. |
Hi There! And there was one by good old Hadley W as well that was good but used the fortify component which i still don’t completely understand. It seems to me that we might need to use ggplot as it seems to handle projection fairly well. I could imagine introducing basic concepts in base R (which we do in the vector lessons) and then having a full tutorial on ggplot maps. UNLESS someone things it’s equally efficient in base r? Looping in @jduckles , @KristinaRiemer , @brymz , @jhollist (Raster group) for additional thoughts! leah :) |
If you are going to be using |
Thanks guys - just to throw this into the mix, DC has a ggplot lesson BUT i've never taught it and can't speak to zack's concerns about it in a 2 day workshop context. NOTE: it does have a time series element BUT nothing associated with spatial data. But as @brymz mentioned, complexity is an absolute concern. Really appreciate the wonderful input from everyone! http://www.datacarpentry.org/R-ecology/05-visualisation-ggplot2.html |
Hey @bbest @megwilliams @kwiter -- did any of you work on creating a map (or have you done this) where you have a shapefile (eg the roads_streams lines shapefile in our data ), and you create a map with the lines colored by category. IN essence "TYPE" or an attribute becomes a factor. We have the following below which seems a bit cumbersome but works. We are using the roads_streams shapefile.
I am not sure how to add a legend or to make a nice categorical plot. Is there a simple way to do and teach this?
Thanks for any ideas!
Here is the latest version of the lesson that i'm working on
https://github.com/data-lessons/NEON-R-Spatial-Vector/blob/gh-pages/00-open-a-shapefile.Rmd
The text was updated successfully, but these errors were encountered: