【发布时间】:2016-08-04 00:56:44
【问题描述】:
我正在尝试使用ggplot2 绘制集群,但出现以下错误
错误:ggplot2 不知道如何处理类因子的数据
我的数据是
samp2
structure(list(PVALUE1 = c(0.000244, 0.000244, 0.001221, 0.000244,
0.000732, 0.000244), PVALUE2 = c(0.000244, 0.000732, 0.000732,
0.000732, 0.001953, 0.000244), PVALUE3 = c(0.000244, 0.001953,
0.001221, 0.000244, 0.000244, 0.000244), PVALUE4 = c(0.000732,
0.000244, 0.000732, 0.000732, 0.001221, 0.000244), PVALUE5 = c(0.000244,
0.000244, 0.001221, 0.000732, 0.005859, 0.000244), PVALUE6 = c(0.000244,
0.00293, 0.001221, 0.303711, 0.00293, 0.000244), PVALUE7 = c(0.000244,
0.00293, 0.000244, 0.000732, 0.000732, 0.000244), PVALUE8 = c(0.000244,
0.001221, 0.000732, 0.000244, 0.001953, 0.000244), PVALUE9 = c(0.000244,
0.000732, 0.000732, 0.000732, 0.00293, 0.000244), PVALUE10 = c(0.000732,
0.01416, 0.000732, 0.001953, 0.001221, 0.000244), PVALUE11 = c(0.000244,
0.000732, 0.000732, 0.005859, 0.001953, 0.000244), cluster = structure(c(2L,
2L, 2L, 2L, 2L, 2L), .Label = c("1", "2"), class = "factor")), .Names = c("PVALUE1",
"PVALUE2", "PVALUE3", "PVALUE4", "PVALUE5", "PVALUE6", "PVALUE7",
"PVALUE8", "PVALUE9", "PVALUE10", "PVALUE11", "cluster"), row.names = c("A2M",
"AAAS", "AACS", "AADAT", "AAGAB", "AAK1"), class = "data.frame")
中心是
centers
PVALUE1 PVALUE2 PVALUE3 PVALUE4 PVALUE5 PVALUE6 PVALUE7 PVALUE8
1 0.49755105 0.56381653 0.56706751 0.5336074 0.54674859 0.54398645 0.56531453 0.58162957
2 0.03481979 0.04874772 0.05312517 0.0447989 0.04720369 0.05724064 0.05257442 0.06362684
PVALUE9 PVALUE10 PVALUE11
1 0.56174089 0.59716210 0.53878320
2 0.04778373 0.06540369 0.04371612
我使用的代码是
ggplot(data=head(samp2$cluster), aes(x=principal_comp1, y=principal_comp2, color=cluster )) +
geom_point()+
geom_point(data=centers, aes(x=V1,y=V2, color='Center')) +
geom_point(data=centers, aes(x=V1,y=V2, color='Center'), size=52, alpha=.2)
如何使它工作。
【问题讨论】:
-
ggplot2 接受数据输入为 data.frane,因此您需要将列表转换为数据框
标签: r ggplot2 cluster-analysis