position = "dodge"
时,我的条形图会堆叠区域。我还注意到颜色是渐变色,并且我不需要渐变色,但是当我尝试使用函数scale_fill_manual(values=c("red","blue", "green", "black"))
时,会收到错误消息Error: Continuous value supplied to discrete scale
。 我已使用此代码对检测区域进行了平均并分配了特定区域:
#Getting total counts per month
dets_per_month = true_dets %>%
group_by(deploy_long, deploy_lat, month, yearcollected, animal_id) %>%
summarize(total_dets = sum(count))
#apply Zone's for specific latitude values
dets_per_month = dets_per_month %>%
mutate(zone =
if_else(deploy_lat <= 44.47833 & deploy_lat >= 44.16253, 1,
if_else(deploy_lat <= 44.15687 & deploy_lat >= 43.67051, 2,
if_else(deploy_lat <= 43.66313 & deploy_lat >= 43.25501, 3, 4)
)))
#Average over month and Zone
dets_per_month = dets_per_month %>%
group_by(zone, deploy_long, deploy_lat, month, yearcollected, animal_id, total_dets) %>%
summarise(ave = mean(total_dets))
而且我已经将此代码用于ggplot条形图:
##Barplot for 3 Years of total detections per month ggplot(dets_per_month, aes(x = dets_per_month$month, y = dets_per_month$ave)) + geom_bar(aes(fill = dets_per_month$zone), position = "dodge", stat = "identity") + xlab("Month") + ylab("Total Detections") + ylim(0, 1750) + facet_wrap(vars(yearcollected)) + facet_grid(yearcollected ~ ., scales="free") + theme_bw() + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(), axis.line = element_line(colour = "black"))
有人知道如何解决此问题吗?
as.factor