Skip to content

Instantly share code, notes, and snippets.

@abikoushi
Created November 3, 2024 01:08
Show Gist options
  • Save abikoushi/bae41f028bab2e19ea025b4fb2064eb2 to your computer and use it in GitHub Desktop.
Save abikoushi/bae41f028bab2e19ea025b4fb2064eb2 to your computer and use it in GitHub Desktop.
parallel coordinate plot with step-line
library(dplyr)
library(tidyr)
library(ggplot2)
library(patchwork)
df1 <- mutate(iris,id=1:n()) %>%
pivot_longer(1:4)
df2 <-reframe(df1, x=c(as.integer(factor(name))-0.25,as.integer(factor(name))+0.25),
y=rep(value,2),
id=rep(id,2),
Species=rep(Species,2))
p2 <- ggplot(df2,aes(x=x,y=y,group=id,colour=Species))+
geom_line(alpha=0.5)+
scale_color_brewer(palette = "Set2")+
theme_bw()
p1 <- ggplot(df1,aes(x=name,y=value,group=id,colour=Species))+
geom_line(alpha=0.5)+
scale_color_brewer(palette = "Set2")+
theme_bw()
p1+p2
ggsave("pcp.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment