problem in y axis in barplot+ggplot
1
0
Entering edit mode
3.3 years ago
hasani.iut6 ▴ 60

Hi every body

I want to plot barplot using ggplot. my data is:

     X1         X2
  2367   تولید کل
    23    هندوانه
    11       خیار
    97       گوجه
     0        سیب
   107       پیاز
     2       کلزا
     0       سویا
     2 آفتابگردان
  748   چغندرقند
    0       پنبه
   22       نخود
    6        عدس
   29      لوبیا
    0        ذرت
    0       برنج
  162         جو
 1152       گندم

I used the following code:

ggplot(data=df, aes(x=X2,y=X1)) +
  geom_bar(stat="identity", fill="steelblue")+
  geom_text(aes(label=X1), vjust=1.6, color="white", size=2)+
  theme_minimal()

and the result is:

enter image description here

the y axis scale is not right. how can I make it right?

barplot ggplot • 1.0k views
ADD COMMENT
1
Entering edit mode

can you try y=as.integer(as.character(X1)) in ggplot code?

ADD REPLY
1
Entering edit mode
3.3 years ago

It is probably encoded as a factor; so, you just need:

df$X1 <- as.numeric(as.character(df$X1))

Kevin

ADD COMMENT
1
Entering edit mode

Thanks, that's work :)

ADD REPLY

Login before adding your answer.

Traffic: 1964 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6