r - 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)
谢谢
解决方案
看起来您的数据列在添加groupColumn
. 为防止您可以groupColumn
从columns
要绘制的中排除:
顺便说一句:不确定一般情况。但至少对于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")
推荐阅读
- php - 虚拟主机显示文件内容而不是为应用程序提供服务
- flutter - 我在运行颤振时遇到了 vs 代码的问题,上面给出了下面给出的“构建失败并出现异常”完整日志
- java - 为什么第一个构造函数在不传递参数的情况下自动运行,即使它不是默认构造函数?
- python - Tkinter 固定框架/画布
- python - python:os.path.join 在抽象类中返回 None
- r - 获取与Dataframe中日期范围对应的名称
- javascript - 电子对话框截断文本
- docker - 如何在 Prometheus Monitoring 的 cadvisor 和 node-exporter 中更改端口号
- java - 在Shape类中定义一个计算图形面积的方法
- python - 如何删除列[Pandas]中具有特定值的N行