0

I keep getting exponents on the y axis and on top of the bar. How do I change it so it stops showing up as exponents. I am also trying to get the y axis to go up to 8 million.

obama <- data.frame(date=c("March 27", "March 31"),
                    enrollment=c(6000000, 7066000))


ggplot(data = obama, aes(x= date, y=enrollment))+
  geom_bar(stat = "identity")+
  ggtitle("Obamacare Enrollment")+
  theme_classic()+
  geom_text(aes(label=enrollment), vjust=-0.3, size=3.5

my obamacare enrollment graph

Elizabeth
  • 15
  • 4

3 Answers3

1

Try barplot with base R and set option(scipen = 999)

options(scipen=999)
p <- barplot(enrollment~date,obama)
with(obama,text(p, enrollment/2, labels = enrollment))

enter image description here

ThomasIsCoding
  • 96,636
  • 9
  • 24
  • 81
1

When using ggplot another option is to suppress scientific notation before plotting using:

options(scipen = 999)

Plot without scientific notation

juljo
  • 634
  • 2
  • 14
1

For the labelling have a look at the scales package which provides e.g. convenience functions label_number and number. The limits of an axis can be set via e.g. the limits argument of the scale:

library(ggplot2)

obama <- data.frame(date=c("March 27", "March 31"),
                    enrollment=c(6000000, 7066000))


ggplot(data = obama, aes(x= date, y=enrollment))+
  geom_bar(stat = "identity")+
  scale_y_continuous(labels = scales::label_number(), limits = c(NA, 8e6)) +
  ggtitle("Obamacare Enrollment")+
  theme_classic()+
  geom_text(aes(label = scales::number(enrollment)), vjust=-0.3, size=3.5)

stefan
  • 90,330
  • 6
  • 25
  • 51