当前位置:网站首页>Ggplot2 drawing learning notes in R

Ggplot2 drawing learning notes in R

2022-07-05 07:15:00 RS&Hydrology

Main records of this paper R In language ggplot2 Drawing package drawing image learning notes .
1.ggplot2 Introduce
ggplot2 The core idea of is to separate drawing and data , Data related plots are separated from data independent plots , Is to draw by layer .

ggplot2 The elements of the diagram can be summarized as follows :
The biggest thing is plot( Refers to the whole picture , Include background and title), The second is axis( Include stick,text,title and stick)、legend( Include backgroud、text、title)、facet This is the second level , among facet It can be divided into external strip part ( Include backgroud and text) And internal panel part ( Include backgroud、boder And gridlines grid, The rough one is grid.major, Thin call grid.minor).

2.ggplot2 Data set and plotting
(1) install ggplot2:Install.packages(“ggplot2”)
(2) call ggplot2:library(“ggplot2”)
(3) Load your own dataset :data("iris")
(4) The plot :

IrisPlot <- ggplot2(iris, aes(Sepal.Length, Petal.Length, colour=Species)) 
   + geom_point()
print(IrisPlot)

understand :

  • The data is iris;
  • Graph attribute mapping :Sepal.Length Corresponding x Axis ,Petal.Length Corresponding y Axis ;
  • Geometry object : Scatter plot ;
  • The plus sign is used to add layer information ;
  • Data and attribute information are contained in ggplot2 Inside .

Reference material :
Book recommendation :https://ggplot2-book.org/getting-started.html
an instruction manual :https://www.tutorialspoint.com/ggplot2/ggplot2_quick_guide.htm

原网站

版权声明
本文为[RS&Hydrology]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140559171703.html