all the columns and labels in y axis stack together in R

20 views Asked by At

I am trying to visualize with ggplot2 in R, with geom_col and geom_text. My problem is that, before I make data labels with geom_text, my visualization is shown properly, as in the following codes and visualizaiton

ggplot(data=highest_lost_products_sales)+
  geom_col(mapping=aes(reorder(productid,-total_profit), y=total_profit),
           fill="seagreen")+
  labs(title = "Highest Lost Products",x="Product IDs",y="Lost profits")

enter image description here

However, when I add the "geom_text" part, the visualization becomes like this"

ggplot(data=highest_lost_products_sales)+
  geom_col(mapping=aes(reorder(productid,-total_profit), y=total_profit),
           fill="seagreen")+
  labs(title = "Highest Lost Products",x="Product IDs",y="Lost profits")+
  geom_text(aes(label=scales::comma(total_profit,accurary=1),
                x=productid, y=total_profit))

enter image description here

I would like to know what happened and how to solve this

0

There are 0 answers