Rotating x axis labels in R for barplot
use optional parameter las=2 . barplot(mytable,main=”Car makes”,ylab=”Freqency”,xlab=”make”,las=2)
use optional parameter las=2 . barplot(mytable,main=”Car makes”,ylab=”Freqency”,xlab=”make”,las=2)
Not sure if it’s what you mean, but you can do this: plot(1:10, xaxt = “n”, xlab=’Some Letters’) axis(1, at=1:10, labels=letters[1:10]) which then gives you the graph:
You can set the horizontal alignment of ticklabels, see the example below. If you imagine a rectangular box around the rotated label, which side of the rectangle do you want to be aligned with the tickpoint? Given your description, you want: ha=”right” n=5 x = np.arange(n) y = np.sin(np.linspace(-3,3,n)) xlabels = [‘Ticklabel %i’ % i … Read more
You don’t need the label_wrap function. Instead use the str_wrap function from the stringr package. You do not provide your df data frame, so I create a simple data frame, one that contains your labels. Then, apply the str_wrap function to the labels. library(ggplot2) library(stringr) df = data.frame(x = c(“label”, “long label”, “very, very long … Read more
The code below provides two potential options for adding year labels. Option 1a: Faceting You could use faceting to mark the years. For example: library(ggplot2) library(lubridate) ggplot(df, aes(Date, value)) + geom_line() + scale_x_date(date_labels=”%b”, date_breaks=”month”, expand=c(0,0)) + facet_grid(~ year(Date), space=”free_x”, scales=”free_x”, switch=”x”) + theme_bw() + theme(strip.placement = “outside”, strip.background = element_rect(fill=NA,colour=”grey50″), panel.spacing=unit(0,”cm”)) Note that with this … Read more
I don’t think modifying a static image will work very well, as it will inevitably lead to registration errors and mismatched styles. Instead, integrate any rendering into the chart’s creation. Using the approach outlined here, the sscce below illustrates a few of the ways to customize the rendered shapes, colors and axes as desired. Addendum: … Read more
The strip.position argument in facet_wrap() and switch argument in facet_grid() since ggplot2 2.2.0 now makes the creation of a simple version of this plot fairly straightforward via faceting. To give the plot the uninterrupted look, set the panel.spacing to 0. Here’s the example using the dataset with a different number of Groups per Category from … Read more