簡體   English   中英

使用ggplot2的多個條形圖

[英]Multiple barplot using ggplot2

根據示例,我嘗試繪制以下內容

數據集如下:

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()+ opts(axis.text.x=theme_text(angle=90)) + 
    opts(title = "Score Distribtion")

和我收到的錯誤:

Error: could not find function "opts"

我嘗試從圖中刪除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