我的数据如下
df<- structure(list(Data = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L,
9L, 10L, 11L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L,
23L, 8L, 12L), .Label = c("A", "B", "C", "D", "E", "F", "G",
"GH", "H", "I", "J", "JJ", "K", "L", "M", "N", "O", "P", "Q",
"S", "T", "U", "V"), class = "factor"), Case1 = c(0.775230796,
0.752114939, 0.738305175, 0.579739531, 0.573781392, 0.572924713,
0.563521221, 0.558172423, 0.557918102, 0.552505171, 0.551921725,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), Case2 = c(NA,
NA, 0.729029032, NA, NA, NA, NA, NA, 0.736282677, 0.702296369,
NA, 0.736060259, 0.735161607, 0.735100052, 0.734870114, 0.732743364,
0.703591649, NA, NA, NA, NA, NA, NA), Case3 = c(NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 0.735568109,
NA, NA, NA, NA, NA), Case4 = c(0.713963088, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 0.781378904,
0.769328289, NA, NA, NA), Case5 = c(NA, NA, NA, NA, 0.693759347,
NA, NA, NA, NA, NA, NA, NA, NA, NA, 0.688396329, NA, NA, NA,
NA, NA, 0.6781535, NA, NA), Case6 = c(0.795781477, 0.793446723,
0.814514206, NA, 0.773564937, NA, NA, 0.783075476, NA, NA, NA,
0.742827684, 0.796443568, NA, 0.75610514, 0.751162004, NA, NA,
NA, NA, NA, 0.738104459, NA), Case7 = c(0.732114731, 0.720226731,
0.782045984, NA, 0.717304483, NA, NA, 0.674992626, NA, NA, NA,
NA, 0.71098987, NA, 0.676952218, NA, NA, NA, NA, NA, NA, NA,
0.676754903)), class = "data.frame", row.names = c(NA, -23L))
我正在尝试删除只有1个值或完全不适用的行 因此,要删除具有完整NA的用户,我可以执行以下
mydf<- df[!(rowSums(is.na(df))),]
我可以这样绘制
library(reshape)
library(ggplot2)
mm <- melt(df, id='Data')
ggplot(data = mm, aes(x = Data, y = value, fill = variable)) +
geom_bar(stat = 'identity', position = 'dodge')
问题是这是条形图,例如,我想在一个点的一行上有一个点图,例如A,并显示case1,case 2,case 3,....的标签。 >
类似的东西
在y轴上为“数据”,在x轴上为“值”,标签为“变量”,其颜色为不同大小
答案 0 :(得分:0)
library(tidyverse)
df %>%
gather(variable, value, -Data) %>%
mutate(value = round(value*100)/100) %>% # Aligns bins to 0.1
ggplot(aes(x = value, fill = variable)) +
geom_dotplot(stackgroups = T)
请注意,点图会固有地将数据四舍五入为bin(否则,除非值完全匹配,否则不会进行叠加)。稍作调整,就可以使ggplot自行选择分级(我认为默认情况下,分级反映了数据范围的1/30)。如果要控制垃圾箱的大小,请使用binwidth
。
我在此处包括binpositions = "all"
,以确保将案例与其他案例放入相同的垃圾箱中,否则它们将使用与其他案例的垃圾箱不对应的自己的垃圾箱,并且不会堆栈。
df %>%
gather(variable, value, -Data) %>%
ggplot(aes(x = value, fill = variable)) +
geom_dotplot(stackgroups = T, binpositions = "all")