1. Create a new text file and name it “Figure 4a dataset.txt”
2. Copy the data below in the text file; save and close
Patients Luminance mean se 0.00 0.0236 7 1 0.00 0.2360 15 1 0.00 2.36 25 1 0.00 23.6 33 1 0.00 236 42 1 1.00 0.0236 5 1 1.00 0.236 14 1 1.00 2.36 24 1 1.00 23.6 32 1 1.00 236 40 1
3. Create a new text file and name it “Figure 4b dataset.txt”
4. Copy the data below in the text file; save and close
Patients D mean se 0.00 0.0236 8 1.5 0.00 0.2360 14 1.5 0.00 2.36 20 1.5 0.00 23.60 24 1.5 0.00 236.00 29 1.5 1.00 0.0236 5 1.5 1.00 0.2360 10 1.5 1.00 2.36 15 1.5 1.00 23.60 20 1.5 1.00 236.00 26 1.5
5. Open RStudio and create a new R script (Ctrl + Shift + N)
6. Copy the syntax below in the R script
7. Insert the right directory of “Ghostscript” into the 7th line (see R Graphs – Preparation) – use “/” instead of “\” to seperate directory levels
8. Insert the right directory of your dataset (see step 1) into the 8th line – use “/” instead of “\” to seperate directory levels
9. Select all (Ctrl + A) and push the “Run” button
10. You should find your high resolution figure in the same directory as your dataset
Now you are ready to play around – use your own dataset or change the syntax and see what happens.
#### This syntax is written by Ronald Bierings - PhD student Ophthalmology UMCG #### #### Questions and/or remarks are welcome (ronaldbierings@gmail.com) #### #=======================================================================================================# #PREPARATION PERIMETRY CENTRAAL Sys.setenv(R_GSCMD="C:/Program Files/gs/gs9.21/bin/gswin32c.exe") #Install Ghostscript and put the right path here setwd("H:/desktop/Figuur 4") cdata_a <- read.table("Figure 4a database.txt",header=T) attach(cdata_a) names(cdata_a) summary(cdata_a) Patient <- factor(Patients) library("ggplot2") library("Rmisc") library("plyr") library("scales") library("gridExtra") library("cowplot") cdata_a #=======================================================================================================# ###################################### SYNTAX TO PLOT GRAPH ####################################### #### POINTS / ERRORBARS / LINES #### p=ggplot( cdata_a, aes(x=Luminance, y=mean, group=Patients, log="x")) + #Plot points x and y, group geom_errorbar(aes(ymin=mean-se, ymax=mean+se), width=.2, size =0.3) + #Plot errobars geom_line(linetype = 2, size = 0.3)+ #Plot line between points geom_point(aes(shape=factor(Patients)), size=2,fill="white") + #Groups have different shapes in graph scale_shape_manual(values=c(16,21), labels=c("Controls", "Patients")) + #Shapes are manually set and labeled #### AXIS #### scale_y_continuous(limits = c(0, 50), breaks=seq(0,60,10), expand = c(0,0)) + #Axis minimum, maximum, breaks scale_x_log10( #Log axis minimum, maximum, breaks #limits = c(0.009,300), breaks = scales::trans_breaks("log10", function(x) 10^x,n=5), labels = scales::trans_format("log10", scales::math_format(10^.x)) ) + #### TITLE / UNIT and QUANTITY #### ggtitle("") + #Title xlab(expression("Luminance "(cd/m^2) )) + #x-axis label ylab("CFF (Hz)") #y-axis label #### LAY-OUT #### fig1a = p + annotate("text", x = 0.01, y = 43, label = "4A", size = 3.5, hjust = 0, vjust =0, fontface =2) + #titel annotate("text", x = 0.01, y = 43, label = " Fovea", size = 2.9, hjust = 0, vjust =0) + #titel theme_bw() + theme( axis.ticks.x = element_line(colour="black", size=0.3), axis.ticks.y = element_line(colour="black", size=0.3), panel.border = element_rect(colour = "black", size=0.6,linetype="solid"), #Black border surrounding graph panel.grid.major = element_blank(), #Major grid lines panel.grid.minor = element_blank(), #Minor grid lines axis.title.x=element_text(size=10, colour="black", vjust=3), #Lay-out x-axis title axis.title.y=element_text(size=10, colour="black", vjust=1), #Lay-out y-axis title axis.text.x=element_text(size=9, colour="black"), #Lay-out x-axis text axis.text.y=element_text(size=9, colour="black"), #Lay-out y-axis text legend.text = element_text(size = 8), legend.position = c(0.8,0.15 ), #Legend position (x,y) panel.background = element_rect (fill = "white"), #Background color legend.background = element_blank(), #Legend text background color legend.key=element_blank(), #Legend shapes background color legend.title = element_blank (), plot.margin = unit(c(0,0.12,0,0.1), "in") #Legend title ) + annotation_logticks(sides = "bt", base=10, size =0.2) #Log ticks on sides #coord_fixed(ratio=1.62/1) #Change ratio of x- and y-axis fig1a #=======================================================================================================# #=======================================================================================================# #PREPARATION PERIMETRY PERIFEER setwd("H:/desktop/Figuur 4") cdata_b <- read.table("Figure 4b database.txt",header=T) attach(cdata_b) names(cdata_b) summary(cdata_b) Patient <- factor(Patients) library("ggplot2") library("Rmisc") library("plyr") library("scales") cdata_b #=======================================================================================================# ###################################### SYNTAX TO PLOT GRAPH ####################################### #### POINTS / ERRORBARS / LINES #### p=ggplot( cdata_b, aes(x=Luminance, y=mean, group=Patients, log="x")) + #Plot points x and y, group geom_errorbar(aes(ymin=mean-se, ymax=mean+se), width=.2, size =0.3) + #Plot errobars geom_line(linetype = 2, size = 0.3)+ #Plot line between points geom_point(aes(shape=factor(Patients)), size=2,fill="white") + #Groups have different shapes in graph scale_shape_manual(values=c(16,21), labels=c("Controls", "Patients")) + #Shapes are manually set and labeled #### AXIS #### scale_y_continuous(limits = c(0, 50), breaks=seq(0,60,10), expand = c(0,0)) + #Axis minimum, maximum, breaks scale_x_log10( #Log axis minimum, maximum, breaks #limits = c(0.009,300), breaks = scales::trans_breaks("log10", function(x) 10^x,n=5), labels = scales::trans_format("log10", scales::math_format(10^.x)) ) + #### TITLE / UNIT and QUANTITY #### ggtitle("") + #Title xlab(expression("Luminance "(cd/m^2) )) + #x-axis label ylab("log CS") #y-axis label #### LAY-OUT #### fig1b = p + annotate("text", x = 0.01, y = 43, label = "4B", size = 3.5, hjust = 0, vjust =0, fontface =2) + #titel annotate("text", x = 0.01, y = 43, label = " Periphery", size = 2.9, hjust = 0, vjust =0) + #titel theme_bw() + theme( axis.ticks.x = element_line(colour="black", size=0.3), axis.ticks.y = element_line(colour="black", size=0.3), panel.border = element_rect(colour = "black", size=0.6,linetype="solid"), #Black border surrounding graph panel.grid.major = element_blank(), #Major grid lines panel.grid.minor = element_blank(), #Minor grid lines axis.title.x=element_text(size=10, colour="black", vjust=3), #Lay-out x-axis title axis.title.y=element_blank(), #Lay-out y-axis title axis.text.x=element_text(size=9, colour="black"), #Lay-out x-axis text axis.text.y=element_text(size=9, colour="black"), #Lay-out y-axis text legend.text = element_text(size = 8), legend.position = c(0.8,0.15 ), #Legend position (x,y) panel.background = element_rect (fill = "white"), #Background color legend.background = element_blank(), #Legend text background color legend.key=element_blank(), #Legend shapes background color legend.title = element_blank (), #Legend title plot.margin = unit(c(0,0.1,0,0), "in") ) + annotation_logticks(sides = "bt", base=10, size =0.2) #Log ticks on sides #coord_fixed(ratio=1.62/1) #Change ratio of x- and y-axis fig1b #=======================================================================================================# ################################ SYNTAX TO SAVE GRAPH AS HQ TIFF ################################## bitmap("Figure 4.tiff", width = 5.0, height = 2.72, units = 'in', type="tifflzw", res=600) #Set width, change height to make graphs squared grid.arrange(fig1a, fig1b, ncol=2, nrow =1, widths=c(1,0.88)) #Ratio of graphs because of margins dev.off() par(mfrow = c(1,1)) #=======================================================================================================#