說,下面的代碼:
x_axe<-c(1,2,3)
y_axe_a<-c(10,20,30)
y_axe_b<-c(100,200,300)
for_barchart<-data.frame(x_axe, y_axe_a, y_axe_b)
chart<-ggplot(data=for_barchart, aes(x=x_axe, y=y_axe_a, color=x_axe))
geom_bar(stat="identity", fill = x_axe, show.legend = FALSE, width = 0.75)
ylim(0,45)
ylab("so and so")
我想要某些顏色的條,但是:
chart scale_fill_manual(values=c("yellow", "red", "blue"))
該圖已創建,但使用默認顏色,而不是指定的顏色。任何人都明白為什么?
uj5u.com熱心網友回復:
將順序分配給列中的不同顏色是一件簡單的事情。
for_barchart<-data.frame(x_axe, y_axe_a, y_axe_b)
for_barchart$colors=c("yellow", "red", "blue")
for_barchart$colors<-factor(for_barchart$colors, levels=c("yellow", "red", "blue"))
library(ggplot2)
(chart<-ggplot(data=for_barchart, aes(x=x_axe, y=y_axe_a))
geom_bar( aes(fill = colors),stat="identity", show.legend = FALSE, width = 0.75)
scale_fill_manual(values=c("yellow", "red", "blue"))
ylim(0,45)
xlab("Groups")
ylab("so and so"))
theme_minimal()
陰謀:

樣本資料:
x_axe<-c(1,2,3)
y_axe_a<-c(10,20,30)
y_axe_b<-c(100,200,300)
Other solution would be if x_axe<-c(1,2,3) are defined as characters x_axe<-c("1","2","3")
Sample code:
(chart<-ggplot(data=for_barchart, aes(x=x_axe, y=y_axe_a, fill=x_axe))
geom_bar(stat="identity", show.legend = FALSE, width = 0.75)
scale_fill_manual(values=c("1"="yellow", "2"="red", "3"="blue"))
ylim(0,45)
xlab("Groups")
ylab("so and so"))
theme_minimal()
Sample data:
x_axe<-c("1","2","3")
y_axe_a<-c(10,20,30)
y_axe_b<-c(100,200,300)
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/445456.html
