我有许多不同的变量:
df_poisson <- structure(list(V1 = c(131L, 38L, 19L, 96L, 13L, 34L),
V2 = c(1L, 1L, 1L, 1L, 0L, 1L), V3 = c(104L,
30L, 20L, 72L, 21L, 62L), V4 = c(20L, 12L, 7L,
14L, 7L, 18L), V5 = c(38L, 9L, 12L, 31L, 10L, 18L), V6 = c(2L,
0L, 1L, 2L, 0L, 7L), V7 = c(293L, 87L, 44L, 217L,
46L, 156L), V8 = c(1L, 0L, 0L, 0L, 0L, 0L), V9 = c(0L,
1L, 0L, 0L, 0L, 0L), V10 = c(1L, 1L, 1L, 0L, 0L,
1L), V11 = c(1L, 1L, 1L, 1L, 1L, 1L), V11 = c(1L,
1L, 1L, 1L, 0L, 1L), V13 = c(4L, 1L, 1L, 0L, 0L, 2L),
V14 = c(0L, 0L, 0L, 0L, 0L, 0L), V15 = c(0L,
0L, 0L, 0L, 0L, 0L), V16 = c(0L, 0L, 0L, 0L, 0L, 0L),
V17 = c(0L, 0L, 0L, 0L, 0L, 0L)), .Names = c("V1",
"V2", "V3", "V4", "V5", "V6",
"V7", "V8", "V9", "V10", "V11",
"V12", "V13", "V14", "V15", "V16",
"V17"), row.names = c(NA, 6L), class = "data.frame")
是否可以在线绘制这17个变量并将17个线泊松图绘制到同一输出中?
答案 0 :(得分:1)
我们需要在Poisson
中为变量生成df_poisson
分布。类似的东西:
#poisson distribution for all columns
df_poisson <- lapply(df_poisson, function(x)ppois(x,1)) %>% as.data.frame()
一旦df_poisson
准备好Poisson
分发,选项就是使用gather
以长格式更改数据。然后使用ggplot
绘制它。
library(tidyverse)
df_poisson %>%
mutate(x = row_number()) %>%
gather(key, value, -x) %>%
ggplot(aes(x, value, color = key)) +
geom_line()