简体   繁体   English

使用ggplot2的多个条形图

[英]Multiple barplot using ggplot2

According to this example I try to plot the following 根据示例,我尝试绘制以下内容

Dataset is the following: 数据集如下:

df <- structure(list(year = 2002:2005, work = c(1L, 2L, 3L, 2L), confid = c(8L, 
5L, 0L, 6L), jrs = c(0L, 3L, 4L, 5L)), .Names = c("year", "work", 
"confid", "jrs"), class = "data.frame", row.names = c(NA, -4L
))

The code in order to plot: 为了绘制代码:

library(ggplot2)
library(reshape)
md <- melt(df, id=(c("year")))
temp.plot<-ggplot(data=md, aes(x=year, y=value, fill=variable) ) + 
    geom_bar()+ opts(axis.text.x=theme_text(angle=90)) + 
    opts(title = "Score Distribtion")

And the error I receive: 和我收到的错误:

Error: could not find function "opts"

I tried to remove the opts() from graph but again I receive the same error. 我尝试从图中删除opts(),但再次收到相同的错误。

What could it be the problem? 可能是什么问题?

An updated version of your code using theme in substitution of opts : 使用theme代替opts代码的更新版本:

df <- structure(list(year = 2002:2005, work = c(1L, 2L, 3L, 2L), confid = c(8L, 
5L, 0L, 6L), jrs = c(0L, 3L, 4L, 5L)), .Names = c("year", "work", 
"confid", "jrs"), class = "data.frame", row.names = c(NA, -4L
))

library(ggplot2)
library(reshape)
md <- melt(df, id=(c("year")))
temp.plot <- ggplot(data=md, aes(x=year, y=value, fill=variable) ) + 
    geom_bar(stat="identity")+ 
    theme(axis.text.x=element_text(angle=90))+ 
    ggtitle("Score Distribtion")

temp.plot

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM