r语言liftchart_R语言--条形图与箱线图

条形图

R语言使用函数barplot()创建条形图。

barplot(H, xlab, ylab, main, names.arg, col)

H是包含在条形图中使用的数值的向量或矩阵。

xlab是x轴的标签。

ylab是y轴的标签。

main是条形图的标题。

names.arg是在每个条下出现的名称的向量。

col用于向图中的条形提供颜色。

若使用多个颜色或names,则使用向量赋值。

另外,超过两个变量表示为用于创建组合条形图和堆叠条形图的矩阵。即使用matrix代替H向量,同时可以添加注释与图例(legend)。

# Create the input vectors.

colors

months

regions

# Create the matrix of the values.

Values

# Give the chart file a name.

png(file = "barchart_stacked.png")

# Create the bar chart.

barplot(Values,main = "total revenue",names.arg = months,xlab = "month",ylab = "revenue",

col = colors)

# Add the legend to the chart.

legend("topleft", regions, cex = 1.3, fill = colors)

# Save the file.

dev.off()

箱线图

箱线图是数据集中的数据分布良好的度量。 它将数据集分成三个四分位数。 此图表表示数据集中的最小值,最大值,中值,第一四分位数和第三四分位数。 它还可用于通过绘制每个数据集的箱线图来比较数据集之间的数据分布。R语言中使用boxplot()函数来创建箱线图。

boxplot(x, data, notch, varwidth, names, main)

x是向量或公式。

数据是数据帧。

notch是逻辑值。 设置为TRUE以绘制凹口。

varwidth是一个逻辑值。 设置为true以绘制与样本大小成比例的框的宽度。

names是将打印在每个箱线图下的一组标签。

main用于给图表标题。

# Give the chart file a name.

png(file = "boxplot.png")

# Plot the chart.

boxplot(mpg ~ cyl, data = mtcars, xlab = "Number of Cylinders",

ylab = "Miles Per Gallon", main = "Mileage Data")

# Save the file.

dev.off()

参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值