0

Below there is a code producing a histogram using ggplot:

ggplot(res, aes(x=TOPIC,y=count)) + 
  scale_y_continuous(expand=c(0,0)) +
  geom_bar(stat='identity') +
  theme(axis.title.x=element_blank()) +
  theme_bw(base_size = 16) +
  ggtitle("Peer-reviewed papers per topic")

res<-structure(list(TOPIC = structure(c(20L, 18L, 21L, 3L, 9L, 4L, 
7L, 8L, 17L, 27L, 29L, 2L, 24L, 30L, 16L, 28L, 10L, 22L, 12L, 
5L, 1L, 19L, 6L, 25L, 11L, 23L, 14L, 15L, 13L, 26L), .Label = c("ANA", 
"BEH", "BOUND", "CC", "DIS", "EVO", "HAB", "HABP", "HARV", "HWC", 
"ISSUE", "METH", "MINOR", "PA", "PEFF", "PHYS", "POLL", "POPABU", 
"POPGEN", "POPSTAT", "POPTR", "PRED", "PROT", "REPEC", "RESIMP", 
"REV", "SHIP", "TEK", "TOUR", "ZOO"), class = "factor"), count = c(9, 
7, 13, 5, 23, 35, 27, 5, 118, 0, 9, 22, 29, 46, 27, 12, 9, 44, 
70, 40, 24, 19, 26, 2, 4, 17, 4, 10, 86, 31)), .Names = c("TOPIC", 
"count"), row.names = c(NA, -30L), class = "data.frame")

The topics have names like "Population status" (POPSTAT), "Population trend" (POPTREND) etc.

There are issues I need help to solve:

1. The theme(axis.title.x=element_blank()) does not remove the x axis title. 
2. The scale_y_continuous(expand=c(0,0)) puts the bar on the level of
   the x-axis, which I need, but I need some expansion on the upper part 
   of the y-axis. How do I achieve that?
3. My labels from the data frame are abbreviations. How do I replace 
   these with new tick labels?
4. I need to turn the x-axis labels 90°. 
Dag
  • 569
  • 2
  • 5
  • 20
  • can you include the dataframe you are plotting using dput(your_dataframe) – pluke Apr 17 '16 at 15:47
  • 1
    Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610). This will make it much easier for others to help you. – Jaap Apr 17 '16 at 16:09

1 Answers1

1
  1. Use labs(x = NULL)

  2. Do you mean ylim? Using this, you can set the limits of the y-axis. Or use scale_y_continuous(limits = c(0, <upperLimit>), expand = c(0, 0))

  3. Use a discrete scale with labels: scale_x_discrete(labels = <axis-labels>, limits = c(1:length(axis-labels))

  4. theme(axis.text.x = element_text(angle = 90))

Daniel
  • 7,252
  • 6
  • 26
  • 38