intl
intl

Reputation: 2773

R - Violin plot x-axis names

I am creating violin plots with lots (will be ~100) of columns (violins). The problem is that the name of each column is very long. What I am doing current is as follows:

jpeg("stats/AllDistanceViolinPlot.jpg", width = 1000, height = 1000);
do.call(vioplot, c(lapply(data, na.omit),list(names=c("veryveryveryverylongname1", "veryveryveryverylongname2", "veryveryveryverylongname4", "veryveryveryverylongname4", "veryveryveryverylongname5", "veryveryveryverylongname6", "veryveryveryverylongname7", "veryveryveryverylongname8"))));
dev.off()

Which gives me this plot:

enter image description here

As you can see, the names of the columns are very long and some actually are not shown. I have also tried something without the list:

jpeg("stats/plot.jpg", width = 1000, height = 1000);
do.call(vioplot, c(lapply(data, na.omit)));
dev.off()

Which gives me this plot:

enter image description here

What I'd like is one of two things:

  1. The names of the columns would be vertical so that they are shown and aren't cut off or
  2. Make the main plot like the second image I posted and have a separate legend that would correlate each column with the full name. For example, something like the following:

    1 - veryveryveryverylongname1 2 - veryveryveryverylongname2 ... 8 - veryveryveryverylongname8

Could someone please suggest the better way (or both) and comment on how to implement them?

Greatly appreciated.

Upvotes: 1

Views: 1700

Answers (1)

IRTFM
IRTFM

Reputation: 263481

Unfortunately the vioplot function in the vioplot package does not accept the usual base graphics parameters for modifying the orientation of axis annotation. You will need to make a new vioplot function and change this code:

if (!horizontal) {
    if (!add) {
        plot.window(xlim = xlim, ylim = ylim)
        axis(2)
        axis(1, at = at, label = label)

To this:

if (!horizontal) {
    if (!add) {
        plot.window(xlim = xlim, ylim = ylim)
        axis(2)
        axis(1, at = at, label = label , las=2)

Upvotes: 3

Related Questions