I'm very new to R and this is my first post asking for help. Hope it works.
I'm trying to make maps using a dataframe that I have. I'm working in RStudio and am using ggplot2 and maps packages. I have a variable in my dataframe called 'Ten year FDI'/ I want to color the map based on that variable, using the following code:
> ggplot(data = Combined_FDI_maps) +
geom_polygon(aes(x = long, y = lat, fill = Ten year FDI, group = group), color = "white") +
coord_fixed(1.3) +
guides(fill=FALSE)
I get two error messages which I don't understand (you can also see the attached image):
Error: unexpected symbol in:
"ggplot(data = Combined_FDI_maps) +
geom_polygon(aes(x = long, y = lat, fill = Ten year"
coord_fixed(1.3) +
guides(fill=FALSE)
Error: Cannot add ggproto objects together. Did you forget to add this object to a ggplot object?
Interestingly, when I change my variable to another one ('region'), then all works our perfectly (you can see the result in the map that is shown in the attached image)
In there any solution to this problem? I would greatly appreciate your support!
Thanks you. Will definitely need to play with the map. Is there an easy way to reduce a polygon? Sorry for a dumb question. I really am extremely newbie to this.
You should be able to filter the Combined_FDI_maps data frame based on some value; as your example is not quite reproducible I can not give a more specific hint.
Also consider that the {maps} package is by now not really bleeding edge stuff, and drawing maps from fortified polygons is no longer considered best practice. It still works, but geom_sf is more flexible and works with the {sf} format, which seems to be the new cool kid.
I won't be able to give you the code here. But, the principle is that if you get it as a dataframe then you can use dplyr to filter out the relevant rows minus the antarctica for the rest of the countries.