2

I draw two charts but want to have the same scale of dots in both for comparision

geofirmen<-data.frame(lon=c(1,2,3), lat=c(1,2,3), freqplz=c(5,10,15))
ggplot(data= geofirmen) + geom_point(aes(x = lon, y = lat, size=freqplz, alpha=.7), colour = "dodgerblue4")

and

geofirmen<-data.frame(lon=c(1,2,3), lat=c(1,2,3), freqplz=c(5,10,20))
ggplot(data= geofirmen) + geom_point(aes(x = lon, y = lat, size=freqplz, alpha=.7), colour = "dodgerblue4")

looks same but is smaller looks same but is bigger

It is i want both have the legend scale of the bigger scale. Attention, the proportion of the graph have not to change since I picture a geografical map but the size of freqplz must be identical for a value of 10 etc. How does this work?

Roland Kofler
  • 1,332
  • 1
  • 16
  • 33

1 Answers1

1

If you really need two separate plots then you can use the same definition of scale_size() for both plots (add to both ggplot() comands) where you define breaks= and also set limits= that contains values of both plots.

+ scale_size(breaks=c(5,10,15,20),limits=c(0,20))

Another solution is to put all data in one data frame that contains grouping column (group in example data). Then add facet_wrap() to make facets for each level. In this case there will be only one legend. coord_fixed() is used to ensure fixed aspect ratio between x and y axis.

geofirmen.new<-data.frame(lon=c(1,2,3,1,2,3), lat=c(1,2,3,1,2,3), 
    freqplz=c(5,10,15,5,10,20),group=c(1,1,1,2,2,2))

ggplot(data= geofirmen.new,aes(x = lon, y = lat, size=freqplz)) + 
    geom_point(alpha=.7, colour = "dodgerblue4") + 
    facet_wrap(~group,ncol=1) + coord_fixed()

enter image description here

Didzis Elferts
  • 95,661
  • 14
  • 264
  • 201