Michel Barbosa
unread,Mar 8, 2009, 2:02:00 PM3/8/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ggplot2
Dear list,
I've succesfully plotted a bubble chart for my restaurant data set. My
"info" dataframe consists of longitude / latitude / rating
My ratings continuous values, but for now I've rounded them off to be
discrete values. My problem is the following. I'd like to use 10 fixed
colours for depicting the ratings. The ratings are between 0 and 10.
Moreover, I'd like the points to scale proportionally to their rating.
This allows me to compare the ratings of the restaurants by looking at
the legend for both the point size and colour. I've struggled with the
aesthetics, but couldn't get it right. My code is as follows. How can
I make sure that let's say, the 10 colours are rainbow(10) AND have
the size depend on the rating?
Kind regards,
Michel
library(ggplot2)
library(Cairo)
lng <- c
(4.482566,4.473565,4.483039,4.474304,4.485887,4.474615,4.497905,4.476821,4.476111,4.481135,4.491674,4.482028,4.483648,4.504239,4.51775,4.517735,4.510746,4.517979,4.477751,4.478252,4.47903,4.479929,4.471585,4.47866,4.478029,4.523455,4.490437,4.486032,4.488442)
lat <- c
(51.913126,51.915905,51.91792,51.916159,51.915666,51.91442,51.921744,51.915445,51.916552,51.916185,51.918877,51.918925,51.91889,51.921842,51.916974,51.916979,51.920805,51.918007,51.909958,51.909476,51.908888,51.909112,51.903885,51.909551,51.906958,51.895308,51.907031,51.901382,51.88934)
rating <- c
(8.0,8.0,8.0,8.0,0.0,9.0,8.0,8.0,9.0,7.0,7.0,7.0,7.0,8.0,9.0,9.0,0.0,8.0,8.0,8.0,7.0,7.0,9.0,8.0,7.0,0.0,6.0,7.0,7.0)
info <- data.frame(lng, lat, rating)
no_margins <- opts(
legend.background = theme_rect(fill = "white", col= "white", size =
4),
legend.position = c(0.9, 0.5),
axis.line = theme_blank(),
axis.text.x = theme_blank(),
axis.text.y = theme_blank(),
axis.ticks = theme_blank(),
axis.title.x = theme_blank(),
axis.title.y = theme_blank(),
axis.ticks.length = unit(0, "cm"),
axis.ticks.margin = unit(0, "cm"),
panel.background = theme_blank(),
panel.border = theme_blank(),
panel.grid.major = theme_blank(),
panel.grid.minor = theme_blank(),
plot.background = theme_blank(),
plot.title = theme_blank(),
plot.margin = unit(c(0, 0, 0, 0), "lines")
)
myplot <- ggplot(data = info, aes(lng, lat)) +
geom_point(aes(size=rating), colour=alpha(rainbow(29), 0.7)) +
scale_size(name='Ratings', limit=c(0, 10), breaks=1:10, to = c(0, 15))
+
coord_cartesian(xlim=c(4.472637176513672, 4.527568817138672), ylim=c
(51.878928367413394, 51.92976563010761)) +
no_margins
Cairo(file="plot.png", type='png', bg='transparent', width=320,
height=480)
print(myplot)