Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Color of gridlines and background

Tags:

r

ggplot2

It seems that this question fist appeared around 2007.

The question is this:

How to change gridline and background color when plotting with ggplot2 in R? I add two pictures as an example on what I mean by background and gridline color.

Back in 2007, Hadley Wickham said that appearance functionalities were missing (this included changing the color of background). Does anybody knows if there's an update that allows to change the background color and the color of gridlines?

Thanks in advance

beforeenter image description here

like image 991
deps_stats Avatar asked May 18 '11 21:05

deps_stats


People also ask

What is the colour of gridlines?

Red colour is used in the topographical map to show grid lines and their numbering.

What color are gridlines in Excel?

Understanding Excel Gridlines Gridlines are displayed in a workbook using a grey color that is applied automatically. If you want o change the gridline colors, Go to the File tab, Options, Advanced and then click Grid Color. Select the color you want to use and then go back to the worksheet.

How do you fill cells with color but keep gridlines?

1. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window. 3. And then save and close the code window, now, when you fill a color for a range of cells, the gridlines will be showed automatically.


1 Answers

Note: Since version 0.9.2 this is done using theme:

theme(panel.background = element_rect(colour = "white"))

Additionally, there are panel.grid.major and panel.grid.minor options. See here for a full list of options and some examples. There is also documentation at ?theme.

In older version of ggplot2 this was done via:

opts(panel.background=theme_rect(colour="white"),...)

You can also switch to more traditional theme using theme_bw().

You can also find information on themes and opts() on this SO thread.

like image 168
joran Avatar answered Sep 28 '22 20:09

joran