This chapter includes text attributes, setting title, graphic size and coordinate axis setting in basic drawing.
The previous article mainly introduced the most basic graphic parameters, symbols, lines and colors, and supplemented the color part first. The last one is the color selected from Set1.
library(RColorBrewer)#call display.brewer.all()#Show what the rcolorbrower palette is
1. Text attributes
(1)cex Specify the text size. The default is 1. The parameter is number. Specifically, specify the font of those parts in the format of cex.XXX.
cex.axis Axis scale text.
cex.lab Axis label
cex.main title
cex.sub Subtitle
(2) Font specifies the font family, size, and typeface. 1 = regular, 2 = bold, 3 = italic, 4 = bold, 5 = symbol font
In the same way as cex above, there is ps : Font point value: 1 point is about 1 / 72 inch, and the final text size is ps*cex. I'm not too sensitive to the specific size; family: font setting. I personally understand what font type is used. I don't know what serif means.
> names(pdfFonts())#See what fonts are available for pdf output [1] "serif" "sans" "mono" [4] "AvantGarde" "Bookman" "Courier" [7] "Helvetica" "Helvetica-Narrow" "NewCenturySchoolbook" [10] "Palatino" "Times" "URWGothic" [13] "URWBookman" "NimbusMon" "NimbusSan" [16] "URWHelvetica" "NimbusSanCond" "CenturySch" [19] "URWPalladio" "NimbusRom" "URWTimes" [22] "ArialMT" "Japan1" "Japan1HeiMin" [25] "Japan1GothicBBB" "Japan1Ryumin" "Korea1" [28] "Korea1deb" "CNS1" "GB1" >
Mapping can be set, which is equivalent to setting the abbreviation of font for ease of use. Shown in the example.
2. Graphic size and boundary
pin: figure width and height; mai: boundary size, bottom left, top right, inches; mar: different from mai unit, English minute. The default value is
c(5,4,4,2)+0.1. You can use par().
Are assigned by numeric vectors.
3. Add title and custom axis
(1) Set inside the drawing function. recommend.
dose<-c(2,4,6,8,10) drugA<-c(5,10,15,18,20) drugB<-c(3,7,12,18,25) p1<-plot(dose,drugA,type = "b",col = "blue",lty = 2,pch = 16,lwd = 2,#In the previous section, we talked about these parameters main = "Trials for DrugA",col.main = "red",cex.main = 2,font.main = 2,#Set main title related information sub = "p1,This data is made up by xyf",col.sub = "pink",font.sub = 3, xlab = "Dosage",ylab = "Drug_Response",#Horizontal and vertical axis label cex.axis =1.5,cex.lab = 1.5,#Scale and label text size xlim = c(0,12),ylim = c(0,30),#set range mai = c(0.5,0.5,1,1)#The distance between the picture and the label title can be set when necessary )
(2) Set outside the mapping function, title(); axis(). Erase the default before use, otherwise it will be added directly.
plot(dose,drugA,type = "b",lty = 3,pch = 16,ann = F)#ann = F, erase the original title title(main = "DrugA",sub = "p1,This data is made up by xyf", col.sub = "pink",font.sub = 3,#Pink, italic. xlab = "Dosage",ylab = "Drug_Response",col.lab = "blue")
The coordinate axes in the figure above are used by default. Now try to erase them all and reset them.
plot(c(0,2,4,6,8,10),c(0,5,10,15,18,20),type = "b",lty = 3,pch = 16,ann = F,axes = F)#Only lines and points axis(side = 2,#Left plus scale at = c(seq(0,24,4)),#Where do you want to add it labels = NULL,#There is no need to set it here, just use the number in at lty = 1,pos = c(0,0),#Where does it intersect another axis col = "blue",las = 2#Vertical axis ) axis(side = 1,#Add scale down at = c(seq(0,12,2)),#Where do you want to add it labels = NULL,#There is no need to set it here, just use the number in at lty = 1,pos = c(0,0),#Where does it intersect another axis col = "blue",las = 0#Parallel to axis ) title(main = "DrugA",sub = "p1,This data is made up by xyf", col.sub = "pink",font.sub = 3,#Pink, italic. xlab = "Dosage",ylab = "Drug_Response",col.lab = "blue")
I have to say that it's tiring and laborious. It's still (1) more convenient. Personally, I think.
(4) Guides and legends
Ah, that's it first. Write the next one next time. Have a rest at the weekend.
Welcome to praise, encourage, exchange and learn, criticize and correct~