-1
您可以使用ggplot2軟件包和mat
矩陣中的數據創建以下barplot嗎?使用ggplot創建barplot
mat <- matrix(c(70.93,78.58,78.72,69.24,62.53,43.85,83.49,70.00,78.30,78.11,71.16,63.82,47.37,89.87),ncol=2)
colnames(mat) <- c("Crude","Standardized")
rownames(mat) <- 2006:2012
library(gplots)
library(RColorBrewer)
my_palette <- palette(brewer.pal(7,"Set1"))
barplot2(mat,
main="Crude and Standardized Rates",
xlab="Type", ylab="Rate", xlim=c(0,20), ylim=c(40,100),
col=my_palette, beside=TRUE, plot.grid = TRUE, xpd=FALSE)
legend(locator(1), rownames(mat), title ="Year",fill=my_palette)
謝謝你這不失真位置代表了自己的價值。我的一個問題是,我無法將y軸的極限值設置爲c(40,100),就像我發佈的圖中一樣。你能告訴我該怎麼做嗎? – Brani
當我給出一個「+ scale_y_continuous(限制= c(40,100))」的限制是可以的,但情節消失。 – Brani
@Brani改爲使用'coord_cartesian'。但要注意的是,只有展示這些酒吧的頂部,在嚴肅的圖形專家中通常被認爲是相當不好的做法。 – joran