1. Create a new text file and name it “Figure 3 dataset.txt”
2. Copy the data below in the text file; save and close
Gender Condition Difference CI_low CI_high 0 1 5 1 9 0 2 65 55 75 0 3 60 50 70 0 4 50 40 60 0 5 35 25 45 1 1 4 0 8 1 2 60 50 70 1 3 55 45 65 1 4 45 35 55 1 5 30 20 40
3. Open RStudio and create a new R script (Ctrl + Shift + N)
4. Copy the syntax below in the R script
5. Insert the right directory of “Ghostscript” into the 7th line (see R Graphs – Preparation) – use “/” instead of “\” to seperate directory levels
6. Insert the right directory of your dataset (see step 1) into the 8th line – use “/” instead of “\” to seperate directory levels
7. Select all (Ctrl + A) and push the “Run” button
8. 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 FIGURE 3 Sys.setenv(R_GSCMD="C:/Program Files/gs/gs9.21/bin/gswin64c.exe") #Install Ghostscript and put the right path here (NB: "/" and not"\") setwd("H:/Desktop") #Sets directory file (NB: "/" and not"\") data <- read.table("Figure 3 dataset.txt",header=T) #Loads dataset attach(data) #Makes dataset active names(data) #Shows names of variables summary(data) #Gives summary of dataset data #Gives whole dataset Gender <- factor(Gender) #Categorical variable (standard: quantitative) library("ggplot2") #Loads package library("Rmisc") #Loads package library("plyr") #Loads package library("scales") #Loads package library("gridExtra") #Loads package library("cowplot") #Loads package ###################################### SYNTAX TO PLOT GRAPH ####################################### #### POINTS / ERRORBARS / LINES #### p=ggplot( data, aes(x=Condition, y=Difference, group=Gender)) + #Plot points x and y, group #geom_smooth(method=lm, se=TRUE, fill="grey85", linetype=0, fullrange=TRUE) + #Add regression se interval without line. geom_errorbar(aes(ymin=CI_low, ymax=CI_high), width=.4, position=position_dodge(width=0.4)) + #Plot errobars #geom_line(linetype = 2)+ #Plot line between points geom_point(aes(shape=factor(Gender)), size=6,fill="white", position=position_dodge(width=0.4)) + #Groups have different shapes in graph scale_shape_manual(values=c(16,21), labels=c("Women", "Men")) + #Shapes are manually set and labeled #### AXIS #### scale_y_continuous(limits = c(0, 100), breaks=seq(0,100,10), expand = c(0,0)) + #Axis minimum, maximum, breaks scale_x_continuous( #Log axis minimum, maximum, breaks breaks=seq(1,5,1), #limits = c(0.009,300), labels = c("Optimal \n luminance","Low \n luminance","High \n luminance","Sudden \n decrease \n ", "Sudden \n increase \n ") ) + #### TITLE / UNIT and QUANTITY #### ggtitle("") + #Title xlab("Luminance condition") + #x-axis label ylab("Difference in complaints \n between patients and controls (%)") #y-axis label #### LAY-OUT #### fig3= p + annotate("text", x = 0.6, y = 94, label = "Figure 3", size = 8, hjust=0, fontface=2) + theme_bw() + theme( axis.ticks.x = element_blank(), axis.ticks.y = element_line(colour="black"), panel.border = element_rect(colour = "black"), #Black border surrounding graph panel.grid.major.x = element_blank() , #No vertical gridlines panel.grid.major.y = element_line(colour = "gray95"), #Major grid lines panel.grid.minor = element_blank(), #Minor grid lines axis.line = element_line(colour = "black"), #Lay-out axis lines axis.title.x=element_text(size=25, colour="black"), #Lay-out x-axis title axis.title.y=element_text(size=25, colour="black"), #Lay-out y-axis title axis.text.x=element_text(size=17, colour="black"), #Lay-out x-axis text axis.text.y=element_text(size=20, colour="black"), #Lay-out y-axis text legend.text = element_text(size = 20), legend.position = c(0.8,0.907 ), #Legend position (x,y) panel.background = element_rect (fill = "white"), #Background color legend.background = element_blank(), #Legend text background color legend.key.size = unit(2, 'lines'), legend.key=element_blank(), #Legend shapes background color legend.title = element_blank (), #Legend title plot.margin = unit(c(0,0.2,0.2,0.1), "in") #Margins ) #annotation_logticks(sides = "bt", base=10) + #Log ticks on sides #coord_fixed(ratio=1/20.6) #Change ratio of x- and y-axis fig3 # 450*450 # #=======================================================================================================# bitmap("Figure 3.tiff", width = 7.5, height = 7.5, units = 'in', type="tifflzw", res=600) grid.arrange(fig3,ncol=1, nrow =1) dev.off() par(mfrow = c(1,1)) ####Look in the directory of your database and find Figure 2.tiff #### #=======================================================================================================#