I'm having issues with changing the size of the title, X-Y labels, X-Y axis text for my ggplot2
. I'm using ggsave
to save the plot as a jpg.
p <- ggplot()
p + theme(axis.title = element_text(size=30), axis.text.y = element_text(size=30),
axis.text.x = element_text(size=30))
but changing the sizes of these texts doesn't change anything on the plot. Would anyone know how to properly change the text sizes?
So I fixed the issue I was having so the changes I make to theme are not affecting the plot (I've tested with changing text color), however the size of the axis text still does not change.
p <- ggplot(d[d$user==i,], aes(x=date, y=url, group=user, label=user)) + geom_line() + geom_point() +
labs(list(title=i, x="Date and Time", y = "URL")) + # Plot labels
axis.POSIXct(1, at=seq(daterange[1], daterange[2], by="hour")) # Set x axis range to first and last date-time in data
p <- p + modifiedtheme
ggsave(plot = p, filename = "sample.jpg", height=2, width=6)
How can I change the default font size in ggplot2? Set base_size in the theme you're using, which is theme_gray() by default. The base font size is 11 pts by default. You can change it with the base_size argument in the theme you're using.
When TRUE (the default), ggsave() will not save images larger than 50x50 inches, to prevent the common error of specifying dimensions in pixels.
To change the font size of text, use cex (character expansion ratio). The default value is 1. To reduce the text size, use a cex value of less than 1; to increase the text size, use a cex value greater than 1.
To increase the width of axes (both X-axis and Y-axis at the same time) using ggplot2 in R, we can use theme function with axis. line argument where we can set element_line argument to a larger value.
Here is a minimal, fully reproducible version of the problem (or lack of any problem, as comments have pointed out). Your own posted code appears to be correct, but maybe this example will help you solve whatever the real problem is:
library(ggplot2)
p1 = ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, colour=Species)) +
geom_point()
p2 = ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, colour=Species)) +
geom_point() +
theme(axis.title=element_text(size=30))
ggsave("figure1.jpg", plot=p1, height=3, width=4, units="in", dpi=150)
ggsave("figure2.jpg", plot=p2, height=3, width=4, units="in", dpi=150)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With