# Change Circle Size According to Value using R

How do I change circle size in a population map according to the population density of the location?

``````library(maptools)
library(RColorBrewer)
library(classInt)
library(maps)

## select color palette and the number colors to represent on the map ##
colors <- brewer.pal(9, "YlOrRd")

#set breaks for the 9 colors
brks<<-classIntervals(pop\$POP10, n=9, style="quantile")
brks<- brks\$brks

map(database='state',regions=c("California"),col="black", lwd=.3, resolution=.1)
points(pop\$LONG, pop\$LAT, pch=21, bg=colors, cex=0.7, lwd=.4)
``````

This way I obtain a map like this. I would like to create a map that shows very small dots for little population density (lighter points in the example) and bigger dots as the population density increases.

• Just change the value of cex to your pop-value. However you should transform them somehow before (could try log-transformation for instance). `points(pop\$LONG, pop\$LAT, pch=21, bg=colors, cex=pop\$POP10, lwd=.4)` Aug 25, 2013 at 14:54
• for instance create a new column in your dataset and log-transform your population data before to get smaller numbers (`pop\$newPop <- log(pop\$POP10)`). Depending on your data this might or might not work. If it doesn't think about creating an quantile interval like you did for the colors and assign it to your population data (`match`). Aug 25, 2013 at 16:00

Thanks to Curlew, I was able to solve my question. I dropped the color distinctions, to allow for publication on a b/w environment. Here is what I have done:

``````## I added a new column with logarithmic data ##
pop[,4]<-log(pop[,1])

## I changed my mind and decided to work still with non-logarithmic data ##
map(database='state',regions=c("California"),col="black", lwd=.3, resolution=.1)
points(pop\$LONG, pop\$LAT, pch=21, bg=24, cex=pop\$POP10/50000, lwd=.4)
``````

And here is my result: Three more questions (not sure if it is appropriate to ask further questions here, though):

• is it ok to work with non-logarithmic data?

• how do I know what values to add in the legend?

• is there a way to plot city names only for the main cities? I know I should include those in the matrix first; after that, how do I do that? And most of all, is that recommendable in such a messy map like this one?

• It's typically frowned upon to post questions in an answer. Please edit your answer and post the new questions separately. They seem different enough to me that you can ask them as 3 seperate questions.
– Fezter
Aug 25, 2013 at 22:57
• Generally you should scale the symbol sizes by the square root of the quantity they display, as in `..., cex=sqrt(pop\$POP10/50000)...`, so that the symbol areas are directly proportional to the quantities. Sep 28, 2013 at 19:21

The easiest way I find is to say

``````points(workbook\$lat,workbook\$long, cex=as.numeric(workbook\$variable.of.interest))
``````

Or, if you want to increase the size of all the points, by, say, a factor of 2:

``````points(workbook\$lat,workbook\$long,cex=2*as.numeric(workbook\$variable.of.interest))
``````