ggplot2: How to reposition break lines next to bars in geom_bar instead of at the middle of the bar?
up vote
0
down vote
favorite
I have the following figure.
As you can see the breaklines for the x scale (which is scaled discrete in this case) go right through the different bars. I want to these breaklines to form "lanes" in which the bars are nicely fitted. So instead of having my breaks go through the bar, I would like them to lie at the edge of each bar.
I experimented a lot with the scale_x_discrete function but just can't seem to figure out how to achieve this...
r ggplot2 geom-bar
add a comment |
up vote
0
down vote
favorite
I have the following figure.
As you can see the breaklines for the x scale (which is scaled discrete in this case) go right through the different bars. I want to these breaklines to form "lanes" in which the bars are nicely fitted. So instead of having my breaks go through the bar, I would like them to lie at the edge of each bar.
I experimented a lot with the scale_x_discrete function but just can't seem to figure out how to achieve this...
r ggplot2 geom-bar
Welcome to SO! Could you make your problem reproducible by sharing a sample of your data and the code you're working on so others can help (please do not usestr()
,head()
or screenshot)? You can use thereprex
anddatapasta
packages to assist you with that. See also Help me Help you & How to make a great R reproducible example?
– Tung
Nov 21 at 13:26
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have the following figure.
As you can see the breaklines for the x scale (which is scaled discrete in this case) go right through the different bars. I want to these breaklines to form "lanes" in which the bars are nicely fitted. So instead of having my breaks go through the bar, I would like them to lie at the edge of each bar.
I experimented a lot with the scale_x_discrete function but just can't seem to figure out how to achieve this...
r ggplot2 geom-bar
I have the following figure.
As you can see the breaklines for the x scale (which is scaled discrete in this case) go right through the different bars. I want to these breaklines to form "lanes" in which the bars are nicely fitted. So instead of having my breaks go through the bar, I would like them to lie at the edge of each bar.
I experimented a lot with the scale_x_discrete function but just can't seem to figure out how to achieve this...
r ggplot2 geom-bar
r ggplot2 geom-bar
edited Nov 21 at 13:16
Jordo82
34718
34718
asked Nov 21 at 12:21
WBM
32
32
Welcome to SO! Could you make your problem reproducible by sharing a sample of your data and the code you're working on so others can help (please do not usestr()
,head()
or screenshot)? You can use thereprex
anddatapasta
packages to assist you with that. See also Help me Help you & How to make a great R reproducible example?
– Tung
Nov 21 at 13:26
add a comment |
Welcome to SO! Could you make your problem reproducible by sharing a sample of your data and the code you're working on so others can help (please do not usestr()
,head()
or screenshot)? You can use thereprex
anddatapasta
packages to assist you with that. See also Help me Help you & How to make a great R reproducible example?
– Tung
Nov 21 at 13:26
Welcome to SO! Could you make your problem reproducible by sharing a sample of your data and the code you're working on so others can help (please do not use
str()
, head()
or screenshot)? You can use the reprex
and datapasta
packages to assist you with that. See also Help me Help you & How to make a great R reproducible example?– Tung
Nov 21 at 13:26
Welcome to SO! Could you make your problem reproducible by sharing a sample of your data and the code you're working on so others can help (please do not use
str()
, head()
or screenshot)? You can use the reprex
and datapasta
packages to assist you with that. See also Help me Help you & How to make a great R reproducible example?– Tung
Nov 21 at 13:26
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
You can create some fake gridlines using geom_vline
while hiding the true gridlines.
library(tidyverse)
data <- data.frame(x = letters[1:10], y = runif(10), stringsAsFactors = FALSE)
data %>%
ggplot(aes(x, y)) +
geom_bar(stat = "identity") +
coord_flip() +
geom_vline(xintercept = seq(1.5, 9.5, 1), color = "white") +
theme(panel.grid = element_blank())
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
You can create some fake gridlines using geom_vline
while hiding the true gridlines.
library(tidyverse)
data <- data.frame(x = letters[1:10], y = runif(10), stringsAsFactors = FALSE)
data %>%
ggplot(aes(x, y)) +
geom_bar(stat = "identity") +
coord_flip() +
geom_vline(xintercept = seq(1.5, 9.5, 1), color = "white") +
theme(panel.grid = element_blank())
add a comment |
up vote
1
down vote
accepted
You can create some fake gridlines using geom_vline
while hiding the true gridlines.
library(tidyverse)
data <- data.frame(x = letters[1:10], y = runif(10), stringsAsFactors = FALSE)
data %>%
ggplot(aes(x, y)) +
geom_bar(stat = "identity") +
coord_flip() +
geom_vline(xintercept = seq(1.5, 9.5, 1), color = "white") +
theme(panel.grid = element_blank())
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
You can create some fake gridlines using geom_vline
while hiding the true gridlines.
library(tidyverse)
data <- data.frame(x = letters[1:10], y = runif(10), stringsAsFactors = FALSE)
data %>%
ggplot(aes(x, y)) +
geom_bar(stat = "identity") +
coord_flip() +
geom_vline(xintercept = seq(1.5, 9.5, 1), color = "white") +
theme(panel.grid = element_blank())
You can create some fake gridlines using geom_vline
while hiding the true gridlines.
library(tidyverse)
data <- data.frame(x = letters[1:10], y = runif(10), stringsAsFactors = FALSE)
data %>%
ggplot(aes(x, y)) +
geom_bar(stat = "identity") +
coord_flip() +
geom_vline(xintercept = seq(1.5, 9.5, 1), color = "white") +
theme(panel.grid = element_blank())
answered Nov 21 at 13:31
Jordo82
34718
34718
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53411920%2fggplot2-how-to-reposition-break-lines-next-to-bars-in-geom-bar-instead-of-at-th%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Welcome to SO! Could you make your problem reproducible by sharing a sample of your data and the code you're working on so others can help (please do not use
str()
,head()
or screenshot)? You can use thereprex
anddatapasta
packages to assist you with that. See also Help me Help you & How to make a great R reproducible example?– Tung
Nov 21 at 13:26