需要使用R为大数据绘制条形图

需要使用R为大数据绘制条形图,r,R,我在.csv文件中有以下数据: Name marks1 marks2 xy 10 30 yz 20 40 zx 30 40 vx 20 20 vt 10 20 如何绘制y轴上同时有marks1和marks2且x轴上有名称的图形 y <- cbind(data$marks1,data$marks2) x <- cbind(data$Name) matplot(x,y,type="p") y您想

我在.csv文件中有以下数据:

Name  marks1 marks2    
xy      10    30
yz      20    40
zx      30    40
vx      20    20
vt      10    20
如何绘制y轴上同时有
marks1
marks2
且x轴上有名称的图形

y <- cbind(data$marks1,data$marks2)
x <- cbind(data$Name)
matplot(x,y,type="p")

y您想要的描述有点混乱,但这是我最好的解释

dat <- read.table(textConnection("Name  marks1 marks2                                                                                  
xy      10    30                                                                                                                       
yz      20    40                                                                                                                       
zx      30    40                                                                                                                       
vx      20    20                                                                                                                       
vt      10    20"), header = TRUE)

library(ggplot2)
library(reshape)

datm <- melt(dat, id.vars = "Name")

datlab <- dat
datlab$y <- datlab$marks1
datlab <- melt(datlab, id.vars = c("Name", "y"))

## set y value to be in the center of the respective bar 
datlab$y <- ifelse(datlab$variable == "marks1", datlab$y / 2, datlab$y + datlab$value / 2)

p <- ggplot() + geom_bar(data = datm, aes(value, x = Name, fill = variable))
p + geom_text(data = datlab, aes(x = Name, y = y, label = value))

dat很抱歉,我需要条形图,其中一种颜色的条形图应表示标记1,另一种颜色的条形图应表示标记2。我有大量的x轴数据,因此名称应适合exactly@user2540455还是没有得到你想要的。你有这样一个情节的例子吗?所有这些数据是否都会出现在一个条形图上,其中颜色区分
marks1
marks2
,阴影(如条形图示例)表示不同级别的名称?在这个图形模型中,有两种颜色白色和黑色在同一个条中,我需要完全相同的,而且我需要x轴标签与条对齐,并且在条上显示标记抱歉延迟回复这是我在使用上述代码时得到的方式任何帮助都会有很大帮助
dat <- read.table(textConnection("Name  marks1 marks2                                                                                  
xy      10    30                                                                                                                       
yz      20    40                                                                                                                       
zx      30    40                                                                                                                       
vx      20    20                                                                                                                       
vt      10    20"), header = TRUE)

library(ggplot2)
library(reshape)

datm <- melt(dat, id.vars = "Name")

datlab <- dat
datlab$y <- datlab$marks1
datlab <- melt(datlab, id.vars = c("Name", "y"))

## set y value to be in the center of the respective bar 
datlab$y <- ifelse(datlab$variable == "marks1", datlab$y / 2, datlab$y + datlab$value / 2)

p <- ggplot() + geom_bar(data = datm, aes(value, x = Name, fill = variable))
p + geom_text(data = datlab, aes(x = Name, y = y, label = value))
datlab <- dat
datlab$y <- rowSums(datlab[c("marks1", "marks2")])
datlab <- melt(datlab, id.vars = c("Name", "y"))
## set y value to be in the center of the respective bar                                                                               
datlab$y <- ifelse(datlab$variable == "marks1", datlab$value / datlab$y / 2, 1 - datlab$value / datlab$y / 2)

p <- ggplot() + geom_bar(data = datm, aes(x = Name, fill = variable, y = value), position = "fill")
p + geom_text(data = datlab, aes(x = Name, y = y, label = value))