5

Is it possible to to remove the top and right border from ggplot2 graphs?

I.e, I'd like to keep the x and y-axis but remove the rest of the black frame that surrounds the graph.

//M

Misha
  • 3,114
  • 8
  • 39
  • 60

2 Answers2

2

You can add this to your plot

+ opts(panel.grid.minor = theme_blank()) 
+ opts(panel.grid.major = theme_blank()) 
+ opts(axis.line = theme_segment())

Since version 0.9.2, opts has been replaced by theme:

+ theme(panel.grid.minor = element_blank()) 
+ theme(panel.grid.major = element_blank()) 
+ theme(axis.line = element_segment())
joran
  • 169,992
  • 32
  • 429
  • 468
Sarah West
  • 2,047
  • 2
  • 20
  • 37
  • I have the following function: theme_white<-function(){theme_update(panel.background=theme_blank(),panel.grid.major=theme_blank(),panel.grid.minor=theme_blank())} I added the axis.line=theme_segment() but I'm still left with black borders...I also tried the opts way but to no avail.. – Misha Mar 28 '11 at 11:50
  • Maybe try to set panel.border=theme_blank() to clean all borders around the plot. – Sarah West Mar 28 '11 at 12:19
  • Can you upload an image so that I can maybe see where the error lies? – Sarah West Mar 28 '11 at 13:13
  • 2
    Finally I found it...panel.background=theme.rect(colour=NA) – Misha Mar 28 '11 at 13:23
2

see this thread, it deals specifically with the problem here

http://groups.google.com/group/ggplot2/browse_thread/thread/f998d113638bf251

and gives a solution that appears to work.

Nelso
  • 36
  • 1
  • 1
    The original code for the helper functions no longer work (because of updates to ggplot, I think), but Rudolf Cardinal has posted this working update: http://egret.psychol.cam.ac.uk/statistics/R/extensions/rnc_ggplot2_border_themes_2013_01.r – Alex Holcombe Jan 17 '13 at 07:29