ggplot2 Version of Figures in “25 Recipes for Getting Started with R”
[This article was first published on YGC » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
In order to provide an option to compare graphs produced by basic internal plot function and ggplot2, I recreated the figures in the book, 25 Recipes for Getting Started with R, with ggplot2.
The code used to create the images is in separate paragraphs, allowing easy comparison.
1.16 Creating a Scatter Plot
plot(cars)
ggplot(cars,aes(speed,dist))+geom_point()
1.17 Creating a Bar Chart
heights
require(gridExtra) heights=ddply(airquality,.(Month), mean) heights$Month=as.character(heights$Month) p1
1.18 Creating a Box Plot
y
ggplot()+geom_boxplot(aes(x=factor(1),y=y))+xlab("")+ylab("")
1.19 Creating a Histogram
data(Cars93, package="MASS") par(mfrow=c(1,2)) hist(Cars93$MPG.city) hist(Cars93$MPG.city, 20)
p
1.23 Diagnosing a Linear Regression
data(iris) m = lm( Sepal.Length ~ Sepal.Width, data=iris) par(mfrow=c(2,2)) plot(m)
r
Related Posts
To leave a comment for the author, please follow the link and comment on their blog: YGC » R.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.