Graphics Reference
In-Depth Information
Figure 8-35. Left: polar plot with line (notice the data range of the radius); right: with the radius
representing a data range starting from zero
The first problem is that the data values (ranging from about 1000 to 2100) are mapped to the
radius such that the smallest data value is at radius 0. We'll fix this by setting the y(or r) limits
from 0 to the maximum data value, as shown in the graph on the right in Figure 8-35 :
# With coord_polar and y (r) limits going to zero
p + coord_polar() + ylim( 0 , max(md$deaths))
The next problem is that the lowest and highest month values, 1 and 12, are shown at the same
angle. We'll fix this by setting the xlimits from 0 to 12, creating the graph on the left in Fig-
ure 8-36 (notice that using xlim() overrides the scale_x_continuous() in p , so it no longer
displays breaks for each month; see Setting the Range of a Continuous Axis for more informa-
tion):
p + coord_polar() + ylim( 0 , max(md$deaths)) + xlim( 0 , 12 )
There's one last issue, which is that the beginning and end aren't connected. To fix that, we need
to modify our data frame by adding one row with a month of 0 that has the same value as the
row with month 12. This will make the starting and ending points the same, as in the graph on
the right in Figure 8-36 (alternatively, we could add a row with month 13, instead of month 0):
# Connect the lines by adding a value for 0 that is the same as 12
mdx <- md[md$month == 12 , ]
mdx$month <- 0
Search WWH ::




Custom Search