How to plot a Bar plot in ggplot2 using R-language -



How to plot a Bar plot in ggplot2 using R-language -

i have info set this:

data repticker 40.87000 actual 603126 38.36000 actual 603168 15.04000 actual 603188 14.07000 actual 603306 7.42000 actual 603328 58.84818 model.pred 603126 41.74658 model.pred 603168 40.30288 model.pred 603188 28.19353 model.pred 603306 60.13398 model.pred 603328

i want plot result this:

my code here, plot 3 stocks.

ggplot(dd, aes(x=repticker, y=data, fill=which)) + geom_bar(stat = "identity", width=0.5, position="dodge", colour="black") + scale_fill_brewer(palette="pastel1")

i think it's because repticker numeric , want treated factor. wrap as.factor follows:

dd <- read.table(text="data repticker 40.87000 actual 603126 38.36000 actual 603168 15.04000 actual 603188 14.07000 actual 603306 7.42000 actual 603328 58.84818 model.pred 603126 41.74658 model.pred 603168 40.30288 model.pred 603188 28.19353 model.pred 603306 60.13398 model.pred 603328", header=true) ggplot(dd, aes(x=as.factor(repticker), y=data, fill=which)) + geom_bar(stat = "identity", width=0.5, position="dodge", colour="black") + scale_fill_brewer(palette="pastel1")

from perspective easier view/compare (as assume purpose) line geom follows:

ggplot(dd, aes(x=as.factor(repticker), y=data, color=which, group=which)) + geom_line(size=1)

a dotplot may useful well.

r ggplot2

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -