Ranae Dietzel and Andee Kaplan
Student: I finished the analysis and look at the great results! What do you think?
Advisor:
aes
gg
theme
ggplot(both, aes(x=year, y=acres, group=crop, color=crop, shape=crop))+
geom_point(size=3)+
geom_smooth()
ggplot(both, aes(x=year, y=acres, group=crop, color=crop, shape=crop))+
geom_point(size=3, alpha = .6)+
geom_smooth()+
ggtitle("Acres of small grains and soybeans in Iowa")
theme_set(theme_bw())
ggplot(both, aes(x=year, y=acres, group=crop, color=crop, shape=crop))+
geom_point(size=3, alpha = .6)+
geom_smooth()+
ggtitle("Acres of small grains and soybeans in Iowa")
library(scales)
##
## Attaching package: 'scales'
## The following objects are masked from 'package:readr':
##
## col_factor, col_numeric
theme_set(theme_bw())
ggplot(both, aes(x=year, y=acres, group=crop, color=crop, shape=crop))+
geom_point(size=3, alpha = .6)+
geom_smooth()+
ggtitle("Acres of small grains and soybeans in Iowa")+
scale_y_continuous(labels = comma)
theme_set(theme_bw())
ggplot(both, aes(x=year, y=acres, group=crop, color=crop, shape=crop))+
geom_point(size=3, alpha = .6)+
geom_smooth()+
ggtitle("Acres of small grains and soybeans in Iowa")+
scale_y_continuous(labels = comma)+
labs(x = "Year",y = "Acres Planted") +
theme(#panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
#panel.background = element_blank(),
axis.line = element_line(),
legend.position=c(.27,.84), legend.title=element_blank(),
legend.text = element_text(size=20),
legend.key.size=unit(1, "cm"),
axis.title.x = element_text(size=22,vjust=-0.5),
axis.title.y = element_text(size=22,angle=90),
axis.text.x = element_text(colour="black", size=20),
axis.text.y = element_text(colour="black", size=20))
my_theme<-theme_bw()+
theme(#panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
#panel.background = element_blank(),
axis.line = element_line(),
legend.position=c(.27,.84), legend.title=element_blank(),
legend.text = element_text(size=20),legend.key.size=unit(1, "cm"),
plot.title = element_text(size = 22, face = "bold"),
axis.title.x = element_text(size=22,vjust=-0.5),
axis.title.y = element_text(size=22,angle=90),
axis.text.x = element_text(colour="black", size=20),
axis.text.y = element_text(colour="black", size=20))
theme_set(my_theme)
ggplot(both, aes(x=year, y=acres, group=crop, color=crop, shape=crop))+
geom_point(size=3, alpha = .6)+
geom_smooth()+
ggtitle("Acres of small grains and soybeans in Iowa")+
scale_y_continuous(labels = comma)+
labs(x = "Year",y = "Acres Planted")
theme_set(my_theme)
ggplot(both, aes(x=year, y=acres, group=crop, color=crop, shape=crop))+
geom_point(size=3, alpha = .6)+
geom_smooth()+
ggtitle("Acres of small grains and soybeans in Iowa")+
scale_y_continuous(labels = comma)+
labs(x = "Year",y = "Acres Planted")+
scale_color_discrete(name="Crop",
breaks=c("smlgrains", "soybeans"),
labels=c("Small Grains", "Soybeans"))+
scale_shape_discrete(name="Crop",
breaks=c("smlgrains", "soybeans"),
labels=c("Small Grains", "Soybeans"))
theme_set(my_theme)
ggplot(both, aes(x=year, y=acres, group=crop, color=crop, shape=crop))+
geom_point(size=3, alpha = .6)+
geom_smooth()+
ggtitle("Acres of small grains and soybeans in Iowa")+
scale_y_continuous(labels = comma)+
labs(x = "Year",y = "Acres Planted")+
scale_color_discrete(name="Crop",
breaks=c("smlgrains", "soybeans"),
labels=c("Small Grains", "Soybeans"))+
scale_shape_discrete(name="Crop",
breaks=c("smlgrains", "soybeans"),
labels=c("Small Grains", "Soybeans"))
ggsave("changes.pdf", plot=cropfig)
or
pdf(file="changes.pdf", height=600, width=600)
cropfig
dev.off()
Can save in many formats – .png, .tiff, .jpg, etc.
Qualitative schemes: no more than 7 colors
Quantitative schemes: use color gradient with only one hue for positive values
Quantitative schemes: use color gradient with two hues for positive and negative values. Gradient should go through a light, neutral color (white)
Small objects or thin lines need more contrast than larger areas
R package based on Cynthia Brewer’s color schemes
ggplot2
scale_colour_discrete
scale_colour_brewer(palette = ...)
scale_colour_gradient
(define low, high values)scale_colour_gradient2
(define low, mid, and high values)scale_fill_...
ggplot(both, aes(x=year, y=acres, group=crop, color=crop, shape=crop))+
geom_point(size=3, alpha = .6)+
geom_smooth()+
ggtitle("Acres of small grains and soybeans in Iowa")+
scale_y_continuous(labels = comma)+
labs(x = "Year",y = "Acres Planted")+
scale_color_brewer(name="Crop",
breaks=c("smlgrains", "soybeans"),
labels=c("Small Grains", "Soybeans"), palette="Set1")+
scale_shape_discrete(name="Crop",
breaks=c("smlgrains", "soybeans"),
labels=c("Small Grains", "Soybeans"))