Hi this is the last piece of my R script I have points on a map I would like to be able to change the points to different colours to reflect organisations and also add a legend to my map reflecting the different organisations
My data headers are
org code, organisation_name, long, lat
ggplot()
geom_polygon(data = worldmap,
aes(x = long, y = lat,
group = group),
fill = 'gray90',
color = 'black')
coord_fixed(ratio = 1.3,
xlim = c(-10,3),
ylim = c(50, 59))
theme_void()
geom_point(data = Data, aes(x = long, y = lat))
CodePudding user response:
I am not from a background of R but if same I need to do in Mobile App
I must pass the lat or long value after removing . and ,- which is 6 digits in the colour parameter
Since the Value of lat and long is of 6 digits and hex code is of also 6 digit #123456 it will always give some new colour but maybe sometimes the same shade of colour if lat and long is nearby
fill = # lat.OnlyNumber(),
color = # lat.OnlyNumber()
CodePudding user response:
you are plotting two different geospatial objects in the ggplot, one is the polygons, the other are points representing organisations. You are correct in using both geom_polygon() and geom_point() in this manner, and keeping the constant, "black" as the polygon colour outside of the aesthetics.
The aesthetics function should not include constants, but rather anything you want to have change, based on the value of some variable, in this case, the name of the organisation. You will need to include the organisation variable as a colour in the aes() for the geom_point().
Although you wish to include the legend, it may be that you have too many organisations, which is why the map disappeared when you added colour as an aesthetic. You can experiment with this by adding:
theme(legend.position = "none")
If this brings back the map, you might want to consider ways of reducing the size of your legend - maybe through font size or something similar, or maybe by grouping organisations together and therefore reducing the number of colours required.
