How can I get a panel with horizontal lines as shown in this plot? I tried all themes but no one provided me with this kind of panel.
Asked
Active
Viewed 263 times
-3
-
Do you mean the y axis grid lines? This depends on the plot (base R `plot`, `ggplot`, ...). You don't provide any data or reproducible code example, so providing help is a guessing game. Please review [how to ask](https://stackoverflow.com/help/how-to-ask) questions, and then edito your question to include a [minimal reproducible example/attempt](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example), including sample data. – Maurits Evers Jun 07 '18 at 23:12
-
Dear Maurits. Thank you. I only mean the grid itself regardless of the data or the plot. I just want the grid to include horizontal lines as shown in the graph. I used this code but I got different theme: ggplot() + geom_bar(aes(x=Year, y=Value, fill=Gender), data = graduates1, stat = "identity", position = "dodge", width = 0.5) + theme_minimal() – Rami_Kh Jun 07 '18 at 23:15
-
Please see my answer below. For future posts, *always* include a minimal representative sample dataset, as detailed in the how to make a minimal reprex link. You'll attract a lot more attention here on SO if you make it as easy as possible for people to help. – Maurits Evers Jun 07 '18 at 23:24
2 Answers
0
We can use panel.grid.major.x
and panel.grid.minor.x
to disable the x
axis grid lines.
Example:
ggplot(iris, aes(x = Species, y = Sepal.Length)) +
geom_bar(stat = "identity") +
theme_minimal() +
theme(
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank())
See here for a comprehensive list of theme
parameters.

Maurits Evers
- 49,617
- 4
- 47
- 68
-
@Rami_Kh This is only a minimal example. Obviously you'll need to adjust it to your actual data (**which you don't provide!**). You control the x-axis grid lines with `panel.grid.major.x` and `panel.grid.minor.x`; this won't change any colours of any bars, nor any y-axis scales! Just add the `+ theme(...)` line to your plot and work from there. – Maurits Evers Jun 07 '18 at 23:28
-
-
You're welcome @Rami_Kh; please consider closing this question by setting the green check mark next to an answer. – Maurits Evers Jun 07 '18 at 23:38
0
Please try to explore existing questions on the same topic. Anyways, it is really simple with ggplot2.
I tried this with mpg data.
library(tidyverse)
plt <- ggplot(mpg, aes(x=displ, y=hwy)) +
geom_point()
plt + theme(panel.border = element_blank(),
panel.grid.minor = element_blank(),
panel.grid.major.x = element_blank())
Now it will change to -
Also look at this link - http://r-statistics.co/

Community
- 1
- 1

akhil sood
- 87
- 6