Graphics Reference
In-Depth Information
is mapped to y(or r), the smallest actual value gets mapped to the center; in other words, the
smallest data value gets mapped to a visual radius value of 0. You may be expecting a data value
of 0 to be mapped to a radius of 0, but to make sure this happens, you'll need to set the limits.
Next, when using a continuous x(or theta), the smallest and largest data values are merged. So-
metimes this is desirable, sometimes not. To change this behavior, you'll need to set the limits.
Finally, the thetavalues of the polar coordinates do not wrap around—it is presently not possible
to have a geom that crosses over the starting angle (usually vertical).
We'll illustrate these issues with an example. The following code creates a data frame from the
mdeaths time series data set and produces the graph shown on the left in Figure 8-35 :
# Put mdeaths time series data into a data frame
md <- data.frame(deaths = as.numeric(mdeaths),
month = as.numeric(cycle(mdeaths)))
# Calculate average number of deaths in each month
library(plyr) # For the ddply() function
md <- ddply(md, "month" , summarise, deaths = mean(deaths))
md
month deaths
1 2129.833
2 2081.333
...
11 1377.667
12 1796.500
# Make the base plot
p <- ggplot(md, aes(x = month, y = deaths)) + geom_line() +
scale_x_continuous(breaks = 1 : 12 )
# With coord_polar
p + coord_polar()
Search WWH ::




Custom Search