r语言峰峦图ggplot2
The area graphs are the plots that demonstrate the quantitative data. R offers the standard function geom_area() to plot the area charts and geom_line() to draw the line over the data points using the ggplot2 package.
面积图是展示定量数据的图。 R提供了标准函数geom_area()来绘制面积图,并提供了geom_line()来使用ggplot2包在数据点上绘制线。
什么是面积图? (What is an area plot?)
An area plot is a kind of line plot which represents the distribution of the quantitative data. In this chart type, we will first mark the data points and then join them by a line to demonstrate the quantity of the data point or value at different time periods.
面积图是一种线图,代表定量数据的分布。 在这种图表类型中,我们将首先标记数据点,然后通过一条线将它们连接起来,以演示不同时间段的数据点或值的数量。
In this tutorial, we are going to create an area chart using the ggplot2 library. Well, if you are aware of using geom_area() function, you are just a few steps away from creating a beautiful area chart in R.
在本教程中,我们将使用ggplot2库创建面积图。 好吧,如果您知道使用geom_area()函数,则距离在R中创建漂亮的面积图仅几步之遥。
Let’s roll!
来吧!
使用ggplot2在R中创建简单区域图 (Create a Simple Area Plot in R using ggplot2)
Let’s plot a simple area chart using the normal distribution values.
让我们使用正态分布值绘制一个简单的面积图。
This is the basic area plot in the R using ggplot2. Here the data is taken as the normal distribution values(rnorm).
这是使用ggplot2在R中的基本面积图。 这里的数据取为正态分布值(rmrm)。
Execute the below code to plot the area chart.
执行以下代码以绘制面积图。
#imports the ggplot2 library
library(ggplot2)
#creates the dataframe having the normal distribution values (rnorm)
xdata<-1:50
ydata<-cumsum(rnorm(50))
data1<-data.frame(xdata,ydata)
#plots the area chart
ggplot(data1, aes(x=xdata, y=ydata))+geom_area(fill='#142F86',alpha=2)
使用ggplot2和hrbrthemes库自定义面积图 (Customizing the area plot using ggplot2 and hrbrthemes libraries)
A simple area chart, as shown above, doesn’t look exciting right? Well, lets put some life into our area chart by adding colors, fonts, styles, and themes.
如上所示,一个简单的面积图看起来并不令人兴奋,对吧? 好吧,让我们通过添加颜色,字体,样式和主题来为我们的区域图增光添彩。
For this, you have to install certain packages such as ggplot2 and hrbrthemes
为此,您必须安装某些软件包,例如ggplot2和hrbrthemes
To install ggplot2 – install.package(‘ggplot2)
安装ggplot2 – ins