Database Reference
In-Depth Information
# Produce a scatterplot of the Old Faithful dataset
plot(faithful)
# Saving the plot as a PNG file using R
# save a 500 X 500 plot
png(filename="old_faithful.png", width=500, height=500, pointsize=16)
plot(faithful)
# This command closes the file
dev.off()
This example produces useful visualizations, but without additional work the stan-
dard R graphics package produces results that are definitely a bit barebones. It's pos-
sible to make core R graphics more aesthetically pleasing, but many people prefer to
look to other libraries for this purpose. For far more complex and aesthetically pleasing
visualizations, a popular choice is the ggplot2 library (see Listing 7.2). ggplot2 tends
to be slightly more verbose to use with simple visualizations such as the scatterplot
example, but when it's used to create more complex data visualizations, it's definitely
well suited to the task. The core idea behind ggplot2 is that the data itself and how it
Figure 7.3 A scatterplot depicting number of eruptions versus waiting
time of “Old Faithful,” using R's sample faithful dataset
 
Search WWH ::




Custom Search