中直方图的绘制与保存

您所在的位置:网站首页 r语言画直方图代码 中直方图的绘制与保存

中直方图的绘制与保存

2023-08-07 02:11| 来源: 网络整理| 查看: 265

直方图表示被存储到范围中的变量的值的频率。直方图类似于条形图,但不同之处在于将值分组为连续范围。直方图中的每个柱表示该范围中存在的值的数量的高度。

R语言使用hist()函数创建直方图。此函数使用向量作为输入,并使用一些更多的参数来绘制直方图。

使用输入vector,label,col和边界参数创建一个简单的直方图。下面给出的脚本将创建并保存当前R语言工作目录中的直方图。

# Create data for the graph.v # Give the chart file a name.png(file = "histogram.png")# Create the histogram.hist(v,xlab = "Weight",col = "yellow",border = "blue")# Save the file.dev.off()

当我们执行上面的代码,它产生以下结果 -

4d425fc97b14df30124447a2c4353f9a.png

X和Y值的范围

要指定X轴和Y轴允许的值的范围,我们可以使用xlim和ylim参数。每个条的宽度可以通过使用间隔来确定。

# Create data for the graph.v # Give the chart file a name.png(file = "histogram_lim_breaks.png")# Create the histogram.hist(v,xlab = "Weight",col = "green",border = "red", xlim = c(0,40), ylim = c(0,5), breaks = 5)# Save the file.dev.off()

当我们执行上面的代码,它产生以下结果 -

61bb999abea624d8549d1347d16f9a96.png

b8d2d8e2d6969bbf5c54d2486ae0e411.png



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3