0
4つの治療で6種の動物の平均訪問率をグラフにしたいと思います。私は各種がその割合を反映する線を持つことを望んでいます。私はこのコードを実行すると:ggplotlyのエラー
library(plotly)
library(RColorBrewer)
library(extrafont)
library(MASS)
library(lme4)
library(reshape2)
dat<-read.table("R-1.AverageVisitationRatewithTrappingPeriod.csv",header=T,sep=",")
melt.data <- melt(dat,id = c("Site", "Treatment", "TrappingPeriod", "Rainfall"),
variable.name="Species",value.name="AverageVisitationRate", na.rm = TRUE)
melt.data$Treatment<-as.factor(melt.data$Treatment)
Treatment<-melt.data$Treatment
Species<-melt.data$Species
AverageVisitationRate<-melt.data$AverageVisitationRate
str(melt.data)
melt.data
plot<- ggplot(melt.data, aes(x = Treatment, y = AverageVisitationRate)) +
geom_point(aes(color = Species)) +
facet_grid(Treatment~Species, margins=FALSE,scales="free_y")+
stat_smooth(method = 'lm',aes(color = Species),se = FALSE)+
labs(list(x = "Treatment", y = "Average Visitation Rate"))+
theme(axis.title = element_text(family = "Arial", color="black", size=20),strip.background = element_blank())
ggplotly(plot)
それは、このエラーを生成します。ここでは Error in $<-.data.frame(
tmpの, "alpha", value = 1) : replacement has 1 row, data has 0
は私のデータのサンプルです:
Treatment Buffalo Impala Nyala Warthog WhiteRhino Wildebeest Zebra
1 - 0% 0 0 0 0 0 0 0
1 - 0% 0.166666667 0.25 0 0.083333333 0 0 0
1 - 0% 0 0.5 0 0 0 0 0
1 - 0% 0 0 0.125 0 0 0 0
1 - 0% 0 0 0.038461538 0.076923077 0.076923077 0 0.038461538
2 - 5% 0.5 0.357142857 0.5 0 0.142857143 0 0
2 - 5% 0 0.25 0.25 0.083333333 0.166666667 0 0
2 - 5% 0 0 0.0625 0 0 0 0
2 - 5% 0 0.2 0 0 0 0 0
2 - 5% 0 0.076923077 0.038461538 0 0.038461538 0 0.153846154
3 - 10% 0.625 0.375 0.5 0.3125 0.5625 0 0.0625
3 - 10% 1.833333333 1.416666667 0.166666667 0.333333333 0 0 0
3 - 10% 0 0 0 0 0 0 0
3 - 10% 0.25 0 0.125 0 0 0 0
3 - 10% 0 1.2 0 0.4 0 0 0
4 - 20% 0 0 0 0 0 0 0
4 - 20% 0.333333333 0.5 0.083333333 0.083333333 0.083333333 0 0
4 - 20% 0 0.1875 0.25 0.125 0 0 0
4 - 20% 0 0.25 0 0 0 0 0
4 - 20% 0.115384615 0.076923077 0.269230769 0.076923077 0.115384615 0 0.115384615
申し訳
私はわからないんだけどここでテーブルをコーディングする方法。
ゼロが多すぎるためにエラーが発生していますか?
...の.csv形式で自分のデータです。 [Rで最小限の再現可能なサンプルを提供する方法](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example#answer-5963610)に従ってください他の人が手助けするのは簡単です。あなたの例は、エラーが出るまでコピー貼り付け可能でなければなりません。 – lukeA
サンプルデータに列がありません。 melt.data < - melt(dat、id = c( "Site"、 "Treatment"、 "TrappingPeriod"、 "Rainfall")、 variable.name = "種"、value.name = "AverageVisitationRate"、na.rm = TRUE)あなたが提示したデータはすでに溶けていると思いますか? – user2945234