aleksander.zawalich
2016-10-19 15:55:59 UTC
I have a question on the plot created with ggplot2 package. Let's say we
have such a plot:
df = data.frame(
numbers = seq(1,5),
labels = c(
"Brand",
"Good Brand",
"The Best Brand",
"The Best Brand Today",
"The Best Brand This Month"
)
)
df = df[order(-df$numbers),]
plot = ggplot(data = df, aes(x=labels, y=numbers))+
geom_bar(stat="identity", fill='orange')+
coord_flip()+
labs(
title = "Exemplary title",
caption = "Exemplary caption 1\nExemplary caption number 2"
)+
theme(
plot.title = element_text(hjust = -0.5),
plot.caption = element_text(hjust = -0.5),
panel.spacing = unit(c(0,0,0,20), "cm")
)
plot
Is there any better way to align title and caption to the left side of a
picture (not plot, but picture, so in this case there where "The best brand
in the world" starts), than making negative vjust values for title and
caption?
It is not really the best solution for two reasons:
- if caption has \n character, it is formatted very strangely and seems
to be dependent on caption length,
- the title length can change, and therefore the vjust values can change
too, so they cannot be constant
--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
To post: email ***@googlegroups.com
To unsubscribe: email ggplot2+***@googlegroups.com
More options: http://groups.google.com/group/ggplot2
---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
have such a plot:
df = data.frame(
numbers = seq(1,5),
labels = c(
"Brand",
"Good Brand",
"The Best Brand",
"The Best Brand Today",
"The Best Brand This Month"
)
)
df = df[order(-df$numbers),]
plot = ggplot(data = df, aes(x=labels, y=numbers))+
geom_bar(stat="identity", fill='orange')+
coord_flip()+
labs(
title = "Exemplary title",
caption = "Exemplary caption 1\nExemplary caption number 2"
)+
theme(
plot.title = element_text(hjust = -0.5),
plot.caption = element_text(hjust = -0.5),
panel.spacing = unit(c(0,0,0,20), "cm")
)
plot
Is there any better way to align title and caption to the left side of a
picture (not plot, but picture, so in this case there where "The best brand
in the world" starts), than making negative vjust values for title and
caption?
It is not really the best solution for two reasons:
- if caption has \n character, it is formatted very strangely and seems
to be dependent on caption length,
- the title length can change, and therefore the vjust values can change
too, so they cannot be constant
--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
To post: email ***@googlegroups.com
To unsubscribe: email ggplot2+***@googlegroups.com
More options: http://groups.google.com/group/ggplot2
---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.