I am new to R, so my problem is simple. I am trying to create a scatterplot that shows data about all countries, and then size the bubbles by population and color them by region. I have accomplished everything except the coloring. Here is my code:
attach(gapminder2)
colors(distinct = FALSE)
radius<-sqrt(gapminder2$Population/pi)
plot(log(`CO2 Emissions per capita`), log(Income), main="PerCapita GDP vs CO2 Emissions by Country", xlab="CO2 Emissions (tons/person)", ylab="Per Capita GDP (US$)")
grid()
symbols(log(`CO2 Emissions per capita`), log(Income), main="PerCapita GDP vs CO2 Emissions by Country", xlab="CO2 Emissions (tons/person)", ylab="Per Capita GDP (US$)", circles=radius, inches=0.25)
All of that runs fine and produces the following graph:
In the dataset (called "gapminder2"), I have a variable "Region". I have tried converting it to a factor variable (Region<- as.factor) but i still don't know how to assign each individual region its own color on the graph (I have 8 different regions).