Graphic Beginner
3.1 Using graphics
In an interactive session, build the graph through a group entry statement until you get the desired effect
Attach (Mtcars) #绑定了数据框mtcarsplot (wt,mpg) #打开图形窗口并生成一副散点图, horizontal walk represents the body weight, the longitudinal axis represents the mileage per gallon of petrol abline (LM (MPT~WT)) # The Fitting function title ("Regression of MPG on Weight") #加标题detach (Mtcars) is obtained from the image drawn in the previous sentence #解除绑定
To save a drawing from code:
Clip the drawing statement between the statement that opens the target graphics device and the statement that closes the target graphics device
PDF ("Mygraph.pdf") #开启目标图形设备的语句
#绘图语句
Attach (Mtcars)
Plot (Wt,mpg)
Abline (LM (MPT~WT))
Title ("Regression of MPG on Weight")
Detach (Mtcars)
Dev.off () #关闭目标图形设备的语句
In addition to PDF (), you can also use Win.metafile (), PNG (), JEPG (), BMP (), TIFF (), XFig (), PostScript (), and save the graphic in a different format
How to save a graphic from the graphical interface: Save As
Issue: When you perform advanced drawing commands such as plot (), hist (), or BoxPlot (), you usually overwrite the previous graphic, create multiple graphics, and view each one at any time.
Solve
Method 1: Open a new graphics window before creating a new drawing
Dev.new () #打开图形设备窗口
Create Diagram statements
Dev.new ()
Create Diagram statements
...
Method 2: View multiple graphs through the graph Habits user interface
When the first graphics window is opened, history-records (recording)--Uses the menu's previous (previous) and Next (Nex) to view the drawing that has been drawn.
Method 3: (for full platform) use the function dev.new (), Dev.next (), Dev.prev (), Dev.set (), Dev.off () to open multiple graphics windows at the same time, and decide which output to send to which window. Specific reference Help (Dev.cur)
3.2 A simple example
A health data set was constructed to describe the response of patients to the five dose levels of the two drugs.
Dose<-c (20,30,40,45,60) druga<-c (16,20,27,40,60) drugb<-c (15,18,25,31,40) mydata1<-data.frame (dose, DRUGA,DRUGB) Mydata1<-rename (mydata1,c (dose= "dose", druga= "response to drug a", drugb= "response to Drug B"))
A different way
"Dose" <-c (20,30,40,45,60) "response to Drug a" <-c (16,20,27,40,60) "Response to Drug B" <-c (15,18,25,31,40) Mydata<-data.frame ( Dose, response to drug a, response to drug B)
The results are as follows
Assuming the first way to draw the data frame, create a graph that describes the relationship between drug a and response
Plot (dose,druga,type= ' B ')
where type= ' B ' indicates simultaneous drawing of points and lines
The first stage of the graphics of R-language combat (chapter III)--Initial knowledge