R 绘制条形图

R 绘制条形图,r,R,我的数据集如下: (10,75) (20,80) (50,85) (100,92) 如何在R中绘制条形图?我在网上看到了许多例子,但没有一个符合这种简单情况。谢谢试试这个: data1=rbind(c(10,20,50,100),c(75,80,85,92)) barplot(data1, beside=TRUE, col=c("blue", "red")) 试试这个: data1=rbind(c(10,20,50,100),c(75,80,85,92)) barplot(data1, bes

我的数据集如下: (10,75) (20,80) (50,85) (100,92)

如何在R中绘制条形图?我在网上看到了许多例子,但没有一个符合这种简单情况。谢谢

试试这个:

data1=rbind(c(10,20,50,100),c(75,80,85,92))
barplot(data1, beside=TRUE, col=c("blue", "red"))
试试这个:

data1=rbind(c(10,20,50,100),c(75,80,85,92))
barplot(data1, beside=TRUE, col=c("blue", "red"))
试试这个:

data1=rbind(c(10,20,50,100),c(75,80,85,92))
barplot(data1, beside=TRUE, col=c("blue", "red"))
试试这个:

data1=rbind(c(10,20,50,100),c(75,80,85,92))
barplot(data1, beside=TRUE, col=c("blue", "red"))

或者,您可以始终使用
ggplot2
库。由于数据的形状,还应使用
restrape2
库来区分变量。在这种情况下会有点复杂,但一般来说,你会得到更好看的条形图

library(ggplot2)
library(reshape2)
#id variable tells what row number is used
data1=as.data.frame(cbind(id=1:4,var1=c(10,20,50,100),var2=c(75,80,85,92)))
#melt will create a row for each variable of each row, except it saves the id as a separate variable that's on every row
data1=melt(data1,id.vars='id')
#ggplot tells what data set is used and which variables do what
#geom_bar tells what type of plot should be used and certain options for the plot 
ggplot(data1,aes(x=id,y=value,fill=variable))+geom_bar(stat='identity',position='dodge')

您也可以使用
ggplot2
库。由于数据的形状,还应使用
restrape2
库来区分变量。在这种情况下会有点复杂,但一般来说,你会得到更好看的条形图

library(ggplot2)
library(reshape2)
#id variable tells what row number is used
data1=as.data.frame(cbind(id=1:4,var1=c(10,20,50,100),var2=c(75,80,85,92)))
#melt will create a row for each variable of each row, except it saves the id as a separate variable that's on every row
data1=melt(data1,id.vars='id')
#ggplot tells what data set is used and which variables do what
#geom_bar tells what type of plot should be used and certain options for the plot 
ggplot(data1,aes(x=id,y=value,fill=variable))+geom_bar(stat='identity',position='dodge')

您也可以使用
ggplot2
库。由于数据的形状,还应使用
restrape2
库来区分变量。在这种情况下会有点复杂,但一般来说,你会得到更好看的条形图

library(ggplot2)
library(reshape2)
#id variable tells what row number is used
data1=as.data.frame(cbind(id=1:4,var1=c(10,20,50,100),var2=c(75,80,85,92)))
#melt will create a row for each variable of each row, except it saves the id as a separate variable that's on every row
data1=melt(data1,id.vars='id')
#ggplot tells what data set is used and which variables do what
#geom_bar tells what type of plot should be used and certain options for the plot 
ggplot(data1,aes(x=id,y=value,fill=variable))+geom_bar(stat='identity',position='dodge')

您也可以使用
ggplot2
库。由于数据的形状,还应使用
restrape2
库来区分变量。在这种情况下会有点复杂,但一般来说,你会得到更好看的条形图

library(ggplot2)
library(reshape2)
#id variable tells what row number is used
data1=as.data.frame(cbind(id=1:4,var1=c(10,20,50,100),var2=c(75,80,85,92)))
#melt will create a row for each variable of each row, except it saves the id as a separate variable that's on every row
data1=melt(data1,id.vars='id')
#ggplot tells what data set is used and which variables do what
#geom_bar tells what type of plot should be used and certain options for the plot 
ggplot(data1,aes(x=id,y=value,fill=variable))+geom_bar(stat='identity',position='dodge')

谢谢你的帮助。如果我写下条形图(data,xlab=“N”,ylab=“特洛伊木马覆盖率”),它也会显示x和y标签。但是酒吧有两种颜色,深色和浅色。为什么?现在,我明白了。但这不是我想要的。这里(10,20,50100)是x轴,(75,80,85,92)是y轴。那我该怎么办呢?我认为默认情况下会显示每组的颜色。如果您想要单一颜色,只需指定它
条形图(data,xlab=“N”,ylab=“特洛伊木马覆盖率”,col=“grey”)
正如我所说,我想要的不是两个相邻的条,而是一个x标签为N=50,y高度为85的条。我希望您能理解我的问题。
plot(c(10,20,50100)、c(75,80,85,92)、type=“h”)
您可以使用plot并指定type=“h”。谢谢CCurtis。如果我写下条形图(data,xlab=“N”,ylab=“特洛伊木马覆盖率”),它也会显示x和y标签。但是酒吧有两种颜色,深色和浅色。为什么?现在,我明白了。但这不是我想要的。这里(10,20,50100)是x轴,(75,80,85,92)是y轴。那我该怎么办呢?我认为默认情况下会显示每组的颜色。如果您想要单一颜色,只需指定它
条形图(data,xlab=“N”,ylab=“特洛伊木马覆盖率”,col=“grey”)
正如我所说,我想要的不是两个相邻的条,而是一个x标签为N=50,y高度为85的条。我希望您能理解我的问题。
plot(c(10,20,50100)、c(75,80,85,92)、type=“h”)
您可以使用plot并指定type=“h”。谢谢CCurtis。如果我写下条形图(data,xlab=“N”,ylab=“特洛伊木马覆盖率”),它也会显示x和y标签。但是酒吧有两种颜色,深色和浅色。为什么?现在,我明白了。但这不是我想要的。这里(10,20,50100)是x轴,(75,80,85,92)是y轴。那我该怎么办呢?我认为默认情况下会显示每组的颜色。如果您想要单一颜色,只需指定它
条形图(data,xlab=“N”,ylab=“特洛伊木马覆盖率”,col=“grey”)
正如我所说,我想要的不是两个相邻的条,而是一个x标签为N=50,y高度为85的条。我希望您能理解我的问题。
plot(c(10,20,50100)、c(75,80,85,92)、type=“h”)
您可以使用plot并指定type=“h”。谢谢CCurtis。如果我写下条形图(data,xlab=“N”,ylab=“特洛伊木马覆盖率”),它也会显示x和y标签。但是酒吧有两种颜色,深色和浅色。为什么?现在,我明白了。但这不是我想要的。这里(10,20,50100)是x轴,(75,80,85,92)是y轴。那我该怎么办呢?我认为默认情况下会显示每组的颜色。如果您想要单一颜色,只需指定它
条形图(data,xlab=“N”,ylab=“特洛伊木马覆盖率”,col=“grey”)
正如我所说,我想要的不是两个相邻的条,而是一个x标签为N=50,y高度为85的条。希望您能理解我的问题。
plot(c(10,20,50100)、c(75,80,85,92)、type=“h”)
您可以使用plot并指定type=“h”。