0
votes

I've made a plot on a map with ggplot. But I've no legend even with specified instructions.

I need to show the correspondence in size point in legend like in the picture below:

img from link

I try to have in legend : points (size='graph') and their value . it's the only type of graph, i've encountered this issue.

Here's my data:

data.frame(
       graph = c(2.5, 1.5, 1.5, 1.5, 1.5, 3, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5,
                 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5),
           x = c(690407.686028692, 668622.75462895, 696803.566124092,
                 673062.214891085, 656077.411408432, 683634.893828692,
                 708826.685978697, 666676.936826137, 680202.347931864,
                 685075.304813531, 702433.968175714, 698431.441510561,
                 676293.390383419, 695645.844602817, 687566.815694649, 663013.779537116,
                 646481.359172896, 638110.223907023, 640715.699972469,
                 642273.74623275),
           y = c(6334609.90229255, 6335374.93429776, 6335888.95948295,
                 6336900.98154074, 6337072.93894301, 6338323.39600256,
                 6341716.94405495, 6345012.80734466, 6345548.51942826,
                 6346087.10440564, 6348894.7081605, 6350228.42781669, 6350778.18047204,
                 6353033.14045844, 6353109.41298154, 6354640.69154103,
                 6360042.46765469, 6360058.68711873, 6360425.02344172,
                 6363722.52659089),
         lat = c(49.3508825326633, 49.3553591808786, 49.3583668130435,
                 49.364287756, 49.3652937402597, 49.3726085383319,
                 49.3924542903226, 49.4117211016949, 49.4148520294118,
                 49.4179995462185, 49.434404050505, 49.4421948987342, 49.4454058876811,
                 49.4585744317618, 49.4590197871622, 49.4679600691824,
                 49.499485003012, 49.4995796297469, 49.5017168409091,
                 49.520950318328),
        long = c(6.20203776633165, 6.00634039793282, 6.25949293478261,
                 6.046220748, 5.89364366233766, 6.1411967388374,
                 6.36749845806452, 5.98886081920904, 6.11036165441177,
                 6.15413617086835, 6.3100716969697, 6.27411638818565, 6.07524689130435,
                 6.24909294540943, 6.17651779391892, 5.95595411740042,
                 5.80744085843373, 5.73224167088608, 5.75564706060606,
                 5.76964322829582)
) -> tmp

Code:

# create map to project on #from package Openstreemap 
library(OpenStreetMap)
dfmap <- openmap(c(min(tmp$lat) - 0.15, min(tmp$long) - 0.15),  
                 c(max(tmp$lat) + 0.15, max(tmp$long) + 0.15),
                 type ="osm")

# projection
autoplot(dfmap) + 
  geom_point(aes(x, y), 
             size = tmp$graph, color = "brown3", 
             data = tmp) +
  theme(axis.line = element_blank(),
        axis.text.x = element_blank(),
        axis.text.y = element_blank(),
        axis.ticks = element_blank(),
        axis.title.x = element_blank(), 
        axis.title.y = element_blank())
Could you provide a working example such that I can test my results? The variable tmp is not defined. Also, to have values displayed in legend, you have to include them in aesthetics: would geom_point(aes(x,y, size=tmp$graph) work better ?Lokinou
Welcome to Stack Overflow! Could you make your problem reproducible by sharing a sample of your data so others can help (please do not use str(), head() or screenshot)? You can use the reprex and datapasta packages to assist you with that. See also Help me Help you & How to make a great R reproducible example?Tung
thanks for your help, i will edit my post to add information asked.Elise Zzz
What package is openmap from? Please include package calls for non-base packages used in your code.Z.Lin
It's from the openstreemap package.Elise Zzz