Polishing Figures

Ranae Dietzel and Andee Kaplan

Polishing Figures

Why

Student: I finished the analysis and look at the great results! What do you think?

Why

Advisor:

Three points on polishing

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"))

Many options to save figures

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.

Colors

Gradients

Qualitative schemes: no more than 7 colors

Quantitative schemes: use color gradient with only one hue for positive values

More Gradients

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

RColorBrewer

R package based on Cynthia Brewer’s color schemes

Color in ggplot2

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"))

Great places to look up what you need (all included by Google)