Graphics Reference
In-Depth Information
See Also
For more on controlling the scaling ratio of the x- and y-axes, see Setting the Scaling Ratio of
the X- and Y-Axes .
Making a Circular Graph
Problem
You want to make a circular graph.
Solution
Use coord_polar() . For this example we'll use the wind data set from gcookbook . It contains
samples of wind speed and direction for every 5 minutes throughout a day. The direction of the
wind is categorized into 15-degree bins, and the speed is categorized into 5 m/s increments:
library(gcookbook) # For the data set
wind
TimeUTC Temp WindAvg WindMax WindDir SpeedCat DirCat
0 3.54
9.52
10.39
89
10 - 15
90
5 3.52
9.10
9.90
92
5 - 10
90
10 3.53
8.73
9.51
92
5 - 10
90
...
2335 6.74
18.98
23.81
250
> 20
255
2340 6.62
17.68
22.05
252
> 20
255
2345 6.22
18.54
23.91
259
> 20
255
We'll plot a count of the number of samples at each SpeedCat and DirCat using
geom_histogram() ( Figure 8-33 ). We'll set binwidth to 15 and make the origin of the his-
togram start at -7.5, so that each bin is centered around 0, 15, 30, etc.:
ggplot(wind, aes(x = DirCat, fill = SpeedCat)) +
geom_histogram(binwidth = 15 , origin = -7.5 ) +
coord_polar() +
scale_x_continuous(limits = c( 0 , 360 ))
Search WWH ::




Custom Search