 user3384265 - 2 years ago 111
R Question

# Equal geom point size in legend in multiple plots with ggplot

Is there a way to equalise the size of geom_points throughout multiple plots, so that they are easily comparable?

ie. I want the size of a 100 value to be equal throughout the plots, regardless of the minimum and maximum value that makes up the size values. As seen below, the size of geom_points are the same, but they represent different values.  ``````graph <- ggplot(mar, aes(x=long, y=lat)) + xlab("Longitude") + ylab("Latitude")
graph  + theme_grey() + geom_point(aes(size=distance\$NEAR_DIST)) + scale_size_area() + labs(size = "Distance from predicted LCP Roman\nroad to known Roman road (m)")
``````

Thanks! Florian

You could achieve that as follows:

``````df1 =data.frame(x=1:20,y=runif(20,1,10),size=runif(20,1,10))
df2 =data.frame(x=1:20,y=runif(20,1,10),size=runif(20,31,40))

maximum = max(c(df1\$size,df2\$size))

graph <- ggplot(df1, aes(x=x, y=y,size=size)) + geom_point() +
scale_size_area(limits=c(1,maximum))

graph2 <- ggplot(df2, aes(x=x, y=y,size=size)) + geom_point() +
scale_size_area(limits=c(1,maximum))
``````

Hope this helps!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download