【问题标题】:Using R I am facing an issue, I tried with this code in katacoda environment but I am not able to move forward使用 R 我遇到了一个问题,我在 katacoda 环境中尝试使用此代码,但我无法继续前进
【发布时间】:2021-03-24 02:52:42
【问题描述】:

1.执行以下任务:
使用内置数据集 mtcars,通过将参数 mfrow 配置为 2,2 并使用以下参数生成 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])

【问题讨论】:

  • 请编辑问题以阐明您在哪里遇到问题,并使您的问题标题更具体地针对该问题。请删除您已经知道如何解决的任何任务(如果它不会导致问题)。如果问题太模糊,我们不知道如何为您提供帮助。
  • 您还可以将适当的 sn-ps 代码移动到其相关任务下,以便更好地说明您尝试对它们执行的操作。
  • 谢谢@LC-datascientist 我不确定答案中的哪一部分代码不正确。这完全是 1 个问题,如果不通过此问题,我将无法继续。

标签: r data-visualization bar-chart pie-chart datavisualization.toolkit


【解决方案1】:
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])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多