我正在尝试制作一个小提琴图,显示不同观察日期的昆虫访问植物品种的次数。我有 25 种不同的植物类型和 16 个不同的连续日期。
尽管(尝试)正确格式化日期,但我不断遇到错误,例如:“as.Date.numeric(value) 中的错误:必须提供'origin'”。这是我的代码:
violin_date<-df, sep = ",", header = TRUE, row.names(1))
violin_date$Date
violin_date$Date <- as.Date.character(violin_date$Date, format =
"%m/%d/%y", origin = 1)
violin_date[, 2:26] <- log(violin_date[2:26])
is.na(violin_date) <- do.call(cbind,lapply(violin_date, is.infinite))
violin_date[is.na(violin_date)] <- 0
violin_date_melt = melt(as.matrix(violin_date))
ggplot (violin_date) + labs(x="Cultivar",y="Date") + geom_violin(aes(x
= variable, y = Date), trim = FALSE) + coord_flip()
我的数据标题如下所示:
Date MTO MY MDO MR MF LSR LY LC
1 2016-07-06 3.895948 2.379877 3.496892 3.825758 2.137259 0.000000 3.829630 4.467857
2 2016-07-07 0.000000 4.448635 2.955516 0.000000 3.275105 0.000000 0.000000 3.592755
3 2016-07-13 6.685971 5.180261 5.459738 6.297448 6.073368 8.222671 7.026091 0.000000
4 2016-07-21 5.327740 6.049159 6.408181 4.745223 6.451136 0.000000 0.000000 0.000000
5 2016-07-25 5.671947 5.102823 4.998650 4.549558 5.604289 0.000000 0.000000 0.000000
6 2016-07-26 5.685996 4.632958 6.095359 5.348789 5.006001 0.000000 0.000000 4.806940
任何帮助表示赞赏!