简体   繁体   中英

Plotting parallel coordinates with confidence intervals in R

Is there an R package allowing to plot parallel coordinates with confidence intervals? Like the example below.

Or what would be the easiest alternative? Making multiple ggplots and printing them side by side with ggarrange or patchwork?

在此处输入图片说明

Generated data

library(tidyverse)

set.seed(1)

#make new data
df = tibble(
  factor= c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O"),
  var1 = rnorm(15, 50, 20),
  var2 = rnorm(15, 10, 4),
  var3 = rnorm(15, 2, 1))

#add confidence intervals
df = df %>% mutate(
  var1_lower = var1 - runif(1, 5, 15),
  var1_upper = var1 + runif(1, 5, 15),
  var2_lower = var2 - runif(1, 0.5, 2.2),
  var2_upper = var2 +  runif(1, 0.5, 2.2),
  var3_lower = var3 - runif(1, 0.1, 0.6),
  var3_upper = var3 + runif(1, 0.1, 0.6))

#reorder columns
df = df[c("factor", "var1", "var1_lower", "var1_upper", "var2", "var2_lower", "var2_upper", "var3", "var3_lower", "var3_upper")]

在此处输入图片说明

There are two libraries that let you plot parallel coordinate charts.

  1. GGally
  2. MASS
  3. ggparci

I believe ggparci would be best fit for you question. As it allows you to plot confidence interval with the data. I have given the link to the library documentation in the comment above.

But, I am mentioning rest two for the benefit of everyone.

In GGally library you can use

ggparcoord(df, columns=1:10, groupColum = 5)

GGally has scale option for further processing of the plot.

I plotted df without any processing and it looks like : 在此处输入图片说明

And in MASS library there is a function called parcoord()

Example use:

# MASS library
library(MASS)

# Color
color <- colors()[as.numeric(iris$Species)*11]

# Plot
parcoord(iris[,c(1:4)] , col= color)

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