Hello,
You must use a categorical variable in 'fill'.
Example: (I also set the fill colours to something else.)
ggplot(data = datax, aes(x = x, y = y, fill = factor(fac))) +
geom_bar(stat = "identity", color = "black",
position = position_dodge()) +
theme_minimal() +
scale_fill_manual(values = c("blue", "red")) +
scale_x_continuous(breaks = 1:12) +
scale_y_discrete(limits = c(0, 100))
Hope this helps,
Rui Barradas
Às 10:50 de 30/07/19, Knut Krueger via R-help escreveu:
Hello to all,
how can I can set both y as character to get the bars beside like
example 1 and use scale_y_continuous
And an additional question: why are the bar colors of x-axes = 8 turned
datax=
data.frame("fac"=c(c(rep(1,10),c(rep(2,10)))),"x"=c(c(1:10,c(1:10))),
"y"=c(89,69,46,57,43,5,83,35,15,19,
51,16,36, 4, 3,3,77, 5,30,61))
ggplot(data=datax, aes(x=x, y=as.character(y), fill=fac)) +
geom_bar(stat="identity", color="black", position=position_dodge())+
theme_minimal()+
scale_x_continuous(breaks=c(1:12)) #+
# scale_y_continuous(limits=c(0, 100))
ggplot(data=datax, aes(x=x, y=y, fill=fac)) +
geom_bar(stat="identity", color="black", position=position_dodge())+
theme_minimal()+
scale_x_continuous(breaks=c(1:12)) +
scale_y_continuous(limits=c(0, 100))
Kind regards Knut
______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.