Hello to ggplot world!

As a PhD student in statistics, I am required to know how to visualize my graphs properly. The more I read Cleveland’s book, the more I understand the importance of good visualizations. I always postponed learning ggplots properly over the last 4 years of graduate school, but now it is the time to tackle this challenge and master it well.

For this blog task, we were required to plot the year versus the log of instructional fee to demonstrate the increasing pattern of tuition increase. I have to say, this is probably the first time I have spend this much time on a plot and have fussed about color and pattern and symbols. But, I assume it is totally worth it. I am not aware of the reasons for the increase, but I am sure it all boils down to the global increase of cost of living in the US.

 

Any ways, since it was the first time I started my plot from scratch with ggplot, I was not sure if the order of events matter. What I mean is that for instance, should I first take care of the THEME and then add the title. If you pay attention to my code, you will realize that I have used THEME a lot throughout the code but I am not sure if it really matters where it should be.

Also, I am not sure how this ggsave is working or if it really worked for my plot. I would like to see other people’s R code just to see how things have worked for them.

 

My R code:

# HW2 Blog Assignment:


Year=c(1960, 1971, 1980, 1990 , 2000, 2010, 2018)
Fees=c(100, 170, 306, 1146, 2157,4161,4548)
log.ten.fees=log(Fees,base=10)
BGSU=cbind.data.frame(Year, Fees, log.ten.fees); View(BGSU)


#Construct a scatterplot of year (horizontal) against log10 of fees with the points connected by lines. 
library(ggplot2)
 
 ggplot(BGSU, aes(x=Year, y=log.ten.fees)) + 
 geom_point(colour = "brown", size = 5, shape=25)+
 geom_line(aes(Year, log.ten.fees), linetype = 1, color="orange", size=2)+ 
 ggtitle("The data consists of Log 10 of instructional fee per semester in BGSU for selected years.
This graph displays the increasing trend of instructional fee throughout the last fifty years 
and the year I got into college.")+
 theme(plot.background = element_rect(fill = "grey90"), plot.title = element_text(colour = "brown", face = "bold",
 size = rel(.7),family = "Helvetica"))+
 geom_vline(xintercept = 2005, linetype = 2,colour="brown", size=1)+
 annotate("text", x=2005, y=2 ,label="In 2005, I started College", colour = "black", size = 3.5)+
 labs(x="YEAR", y="Log Base 10 of Fee")+
 theme(panel.border = element_rect(linetype = "dashed", fill = NA))+
 theme(panel.grid.major = element_line(colour = "white"))+
 theme(panel.grid.minor = element_line(colour = "white"))+
 theme(axis.line = element_line(size = 2, colour = "grey80"))+
 theme(axis.text = element_text(colour = "brown"))+
 theme(axis.title.y = element_text(size = rel(1.2), angle = 90))+
 ggsave("fee.png",width =3.5 , height = 5)
 
 
 
 
 
 
 
 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *