中直方图的绘制与保存 |
您所在的位置:网站首页 › r语言画直方图代码 › 中直方图的绘制与保存 |
直方图表示被存储到范围中的变量的值的频率。直方图类似于条形图,但不同之处在于将值分组为连续范围。直方图中的每个柱表示该范围中存在的值的数量的高度。 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()当我们执行上面的代码,它产生以下结果 - 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()当我们执行上面的代码,它产生以下结果 - |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |