r语言峰峦图ggplot2_如何使用ggplot2在R中创建区域图

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)
Basic Area Plot In R

使用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)

安装ggp​​lot2 – install.package('ggplot2)

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值