首页 > 解决方案 > R:清理 GGally 地块

问题描述

我正在使用 R 编程语言,我是新的 GGally 库。我在线学习了一些基本教程并运行了以下代码:

#load libraries

library(GGally)
library(survival)
library(plotly)

我更改了一些数据类型:

#manipulate the data
data(lung)
data = lung
data$sex = as.factor(data$sex)
data$status = as.factor(data$status)
data$ph.ecog = as.factor(data$ph.ecog)

现在我想象一下:

#make the plots

#I dont know why, but this comes out messy
ggparcoord(data,  groupColumn = "sex")

#Cleaner
ggparcoord(data)

两个 ggparcoord() 代码段都成功运行,但是第一个代码段非常混乱(轴标签似乎已损坏)。有没有办法修复标签?

在第二张图中,很难分辨因子变量在它们各自的轴上是如何标记的(例如,对于“性别”列,底部是“男性”还是底部类型是“女性”)。有谁知道是否有办法解决这个问题?

最后,有没有办法将“ggplotly()”函数用于“ggally”对象?

例如

a = ggparcoord(data)
ggplotly(a)

谢谢

标签: rggplot2plotlydata-visualizationdata-manipulation

解决方案


看起来您的数据列在添加groupColumn. 为防止您可以groupColumncolumns要绘制的中排除:

顺便说一句:不确定一般情况。但至少对于ggparcoord ggplotly作品而言。

library(GGally)
library(survival)
data(lung)
data = lung
data$sex = as.factor(data$sex)
data$status = as.factor(data$status)
data$ph.ecog = as.factor(data$ph.ecog)

#I dont know why, but this comes out messy
ggparcoord(data, seq(ncol(data))[!names(data) %in% "sex"], groupColumn = "sex")


推荐阅读