Wednesday, January 18, 2023

Parts of Graph Adjustment in R

 

1. X and Y-axis's adjustment

s.theme1 <- theme(axis.text.x=element_text(size=12),
                  axis.title.x=element_text(size=18),
                 axis.text.y=element_text(size=18),
                 axis.title.y=element_text(size=18, 
                  face="bold"),
                 legend.text=element_text(size=22), 
                legend.title =element_text(size=22) )

2. Legend adjustment

s.theme2 <- theme(axis.ticks.length=unit(0.4, "cm"),
                 legend.key.width=unit(0.8, "cm"),
                 legend.key.height=unit(0.8, "cm"), 
                 legend.position="",
                 plot.margin = unit(c(1, 1, 1, 1), "lines"),
                 panel.grid.minor=element_blank())

3. Remove grid lines

s.theme3=theme(axis.line = element_line(),
      panel.grid.major = element_blank(),
      panel.grid.minor = element_blank(),
      panel.border = element_blank(),
      panel.background = element_blank())

4. Y lab with full name and units

labs <- c(list(biochar="Biochar",
               SCL=expression("Sodium contents in leaf (%)"),
               carbon=expression('CO'[2]*' emission (mg  cm'^-2*' day'^-1*')'),
               nitrogenn=expression('NO'[2]*' emission (mg  cm'^-2*' day'^-1*')'),
               co=expression('Days of CO'[2]*' emission measurement')))

5. Facet functions

labels <- c('Biochar' = "(a) Biochar", 
            'No Biochar' = "(b) No Biochar")

facet <- facet_wrap(~Biochar, ncol=2, 
                    labeller=labeller(Biochar=labels))

facect.t <- theme(strip.text.x=element_text(size=20, 
                                            angle=360),
                  strip.text.y=element_text(size=20),
                  strip.background=element_rect(colour="black",
                                                fill="white"))

6. Color Selection

n=12
colr=rainbow(n); colt=terrain.colors(n); colc=cm.colors(n)
colh=heat.colors(n); colto=topo.colors(n) par(mfrow=c(2,3))

pie(rep(1,n), col=colr)
pie(rep(1,n), col=colt)
pie(rep(1,n), col=colc)
pie(rep(1,n), col=colh)
pie(rep(1,n), col=colto)
colors <- c(colr[8],colt[3],colt[9],colh[4],colto[7],colc[11], colto[3],colh[8])
7. Select width of bars

pos <- 1.8

8. Save the session

save(list = ls(all=TRUE), file= "D:/R_working/subhan_gases_data//session2")
load(file= "D:/R_working/subhan_gases_data/session2")


No comments:

Post a Comment