) 我试图生成三个散点图,其中的组依赖于列矩阵的名称,以便第一个图包含以A开头的列名的所有值,第二个以B开头,第三个以C开头。 我找到了一种方法,如何根据起始字母(分配给变量" condition")提取数据矩阵的值。不幸的是,我不知道如何仅提取变量名称,以便生成散点图。最小的例子如下:
library(lattice)
library(latticeExtra)
data <- matrix(data= 1:9, nrow = 5, ncol = 9) #produces my matrix
colnames(data) <- c("A1", "A2", "A3", "B1", "B2", "B3", "C1", "C2", "C3")
p <- c(0.1, 0.2, 0.3) #my probabilities
#data contains now my final matrix
mean <- colMeans(data) #taking the mean of the columns
xyplot(mean ~ p , type = "l", lwd=2, xlab = "error rate", ylab = "error magnitude", groups = grep("A", colnames(data))) #scatterplot via lattice-package
任何人都可以帮助我吗?
答案 0 :(得分:0)
你可以尝试
library(tidyverse)
cbind.data.frame(M=mean,P=p) %>%
rownames_to_column() %>%
mutate(rowname=gsub("[[:digit:]]","", rowname)) %>%
ggplot(aes(M,P)) +
geom_point() +
facet_grid(~rowname)