2

I'm trying to create a histogram without a frame (top and right lines), but with x and y axes shown in R using ggplot.

I am using the solution to this question: remove grid, background color and top and right borders from ggplot2

Specifically:

library(ggplot2)
ggplot(faithful, aes(x=eruptions)) + 
    geom_histogram(binwidth=0.2,colour="black",fill="white")+
    theme_bw()+theme(aspect.ratio=0.618)+
    theme(plot.background = element_blank(),
          panel.grid.major = element_blank(),
          panel.border = element_blank())+
    theme(axis.line.y = element_line(color = 'black'))

The last line, however, does not seem to have a visible effect.

To reiterate, I would like: y-axis shown, ticks on the x-axis, and preferably the origin of axes at (0,0).

Community
  • 1
  • 1
Fato39
  • 746
  • 1
  • 11
  • 26
  • Try using `theme_classic()` from very end of linked post. Does this give you what you want? `ggplot(faithful, aes(x=eruptions)) + geom_histogram(binwidth=0.2,colour="black",fill="white")+ theme_classic() + scale_y_continuous(expand=c(0,0))` – user20650 Apr 11 '15 at 21:39
  • Thank you for the comment, @TylerRinker. As far as I can tell, `faitfhul` is a built-in data frame, so the example should work for you as is. (I did add `library(ggplot2)`just to be sure.) – Fato39 Apr 11 '15 at 21:39
  • 1
    Thank you, @user20650. Indeed, that looks exactly like a plot I would like. This was very simple - if you consider this worthy of an answer, I will gladly accept it. – Fato39 Apr 11 '15 at 21:42
  • Great stuff @Fato39; please feel free to write it up an answer (and accept it) – user20650 Apr 11 '15 at 21:46

1 Answers1

2

As @user20650 kindly suggested in the comments, theme_classic() is a simple option to do what I was trying to achieve. Additionally, to move the x-axis just below the bars, scale_y_continuous(expand=c(0,0)) can be used.

Thank you!

Fato39
  • 746
  • 1
  • 11
  • 26