Aligning rotated xticklabels with their respective xticks

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

Wrap long axis labels via labeller=label_wrap in ggplot2

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

Axis labels on two lines with nested x variables (year below months)

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

How can I put axis on a .png file in java?

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

Multirow axis labels with nested grouping variables

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