0

1.执行以下任务:
使用内置数据集 mtcars,通过使用 2,2 配置参数 mfrow 并使用以下参数生成 4 个图形并查看图形是如何绘制的。

mtcars$mpg vs mtcars$cyl
mtcars$mpg vs mtcars$hp
mtcars$mpg vs mtcars$wt
mtcars$mpg vs mtcars$vs

2.执行以下任务:
使用内置数据集Orange,并为列Tree生成条形图。
使用以下条形图。

Name of the chart - Trees count
x-axis - Tree Types
y-axis - count
Ensure that the barplot is red in color.

3.执行以下任务:
将上一步生成的条形图旋转为水平,改变两个轴并将条形图的颜色更改为绿色

4.执行以下任务:
使用内置数据集 mtcars 和列 cyl 和 gear 创建堆叠条形图。

5.执行以下任务:
为 mtcars 数据集的前 6 个条目创建一个饼图。根据数据集的行名(标签)绘制 mpg 值。

我尝试使用此代码,但也许我无法正确理解问题,就像在 katacoda 环境中一样。我无法前进。代码:

data(mtcars)
par(mfrow=c(2,2))
plot(mtcars$mpg,mtcars$cyl)
plot(mtcars$mpg,mtcars$hp)
plot(mtcars$mpg,mtcars$wt)
plot(mtcars$mpg,mtcars$vs)
data(Orange)
plot(Orange$Tree)
count<-table(Orange$Tree)
barplot(count,main="Trees count",xlab="Tree Types",ylab="count",col="Red")
barplot(count,main="Trees count",xlab="count",ylab="Tree Types",col="Green",horiz="TRUE",las=1)
data(mtcars)
plot(mtcars$cyl,mtcars$gear)
data(mtcars)
pie(table(mtcars$mpg[1:6]),labels=row.names(mtcars)[1:6])
4

1 回答 1

0
data(mtcars)
par(mfrow = c(2,2))
plot(mtcars$mpg,mtcars$cyl)
plot(mtcars$mpg,mtcars$hp)
plot(mtcars$mpg,mtcars$wt)
plot(mtcars$mpg,mtcars$vs)
data(Orange)
count<-table(Orange$Tree)
barplot(count, main="Trees count", xlab="Tree Types", ylab="count", col=c("red"))
barplot(count, main="Trees count", xlab="count", ylab="Tree Types", col=c("green"), 
horiz = TRUE)
data(mtcars)
counts <- table(mtcars$cyl, mtcars$gear)
barplot(counts, xlab="cyl", ylab="gear")
pie(table(mtcars$mpg[1:6]),labels=row.names(mtcars)[1:6])
于 2020-12-13T18:37:11.077 回答