Hello I am trying to plot some data using polygons.
Can someone help me with this? This is my first map in R.
Thank you very much!
Hello I am trying to plot some data using polygons.
Can someone help me with this? This is my first map in R.
Thank you very much!
Do you get an error message? How does your plot look compared to what you expect it to look like?
It's a little hard to diagnose the problem without access to your data, but here is an example of how you would do it, using the nc
dataset which is part of the sf
pacakge:
library(tidyverse)
library(sf)
nc <- read_sf(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
nc_sf <- nc %>%
select(FIPS)
nc_data <- nc %>%
st_drop_geometry() %>%
select(FIPS, SID79)
nc_sf %>%
left_join(nc_data, by = "FIPS") %>%
ggplot(aes(fill = SID79)) +
geom_sf()
Created on 2020-05-26 by the reprex package (v0.3.0)
Can you share a sample of your data? If not here, perhaps on GitHub? I'm sure that the problem you are having does not require a 300MB file to demonstrate.
Have you tried specifying the variable name from codecz
that you want to use as the fill variable? In the code above you have fill = 'example'
. I'm not sure what this variable is, but you should write something like fill = my_var
, where my_var
is the column name. Note that I don't use ''
but rather use a bare variable name.
Can you upload an image of the map you are getting as output? Just to be clear, did you try this exact code? And note that example
is not in quotes.
y <- left_join(cz_regions,codecz)
ggplot(data = y) +
geom_sf(aes(fill = example)) +
theme_void()
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.