简体   繁体   中英

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:

在此输入图像描述

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:

在此输入图像描述

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM