Search code examples
rplotmappingsymbolsscaling

Manage Circles size in plot using symbols


I am using symbols function in r to draw cycles in a map, which has been imported as a plot.

According to the function Cycles radius are scaled basted on the max value of the data set.

I am plotting the same map for different time periods (different data set) and i want the maps to be comparable, meaning that the circle radius refers to the same values in all different maps. Is there a way that I can manage circle scaling?

Thanks

This is my code

#for the first map 2010
plot(my_map)
symbols(data2010$Lon, data2010$Lat, circles= data2010$number, inches=0.25,add=T)

#then the map for 2011
plot(my_map)
symbols(data2011$Lon, data2011$Lat, circles= data2011$number, inches=0.25,add=T)

Solution

  • The manual page suggests that setting inches=FALSE will accomplish what you want. Since you did not provide a sample of your data, we have to use data already available. This data set is used in the Examples on the manual page for the symbols() function:

    data(trees)
    str(trees)
    # 'data.frame': 31 obs. of  3 variables:
    #  $ Girth : num  8.3 8.6 8.8 10.5 10.7 10.8 11 11 11.1 11.2 ...
    #  $ Height: num  70 65 63 72 81 83 66 75 80 75 ...
    #  $ Volume: num  10.3 10.3 10.2 16.4 18.8 19.7 15.6 18.2 22.6 19.9 ...
    

    Since we only have one sample, we can plot the the symbols with and without the 31th row which is the largest.

    with(trees, symbols(Height, Volume, circles = Girth/24, inches = FALSE))
    

    Now add the data without row 31:

    with(trees[-31, ], symbols(Height, Volume, circles = Girth/24, fg="red", inches = FALSE, add=TRUE))
    

    We can tell that the scaling is the same because the red circles match the black circles even though the largest girth is missing from the second plot. For this to work you will have to specify the same values for xlim= and ylim= in each plot.

    Run this code again replacing inches=FALSE with inches=.5 to see the difference.

    Figure