问题描述
I have a dataframe which I used the melt function to get to this (length = 118):
record_id value Values
1 8 int_to_out 20
2 14 int_to_out 32
3 5 int_to_out 22
4 6 int_to_out 19
5 31 int_to_out 15
6 48 int_to_out 20
7 100 int_to_out 30
... ... ... ...
113 87 symptom_to_int 7
114 72 symptom_to_int 4
115 99 symptom_to_int 3
116 102 symptom_to_int 36
117 103 symptom_to_int 13
118 111 symptom_to_int 6
我用这个做一个堆积的小图:
该图有59个y元素,我需要根据原始(非熔融)数据向它们添加点。 所以我写了这个:
ggplot(t,aes(y=as.factor(record_id),x=Values,fill=value)) +
geom_bar(position=position_stack(reverse= TRUE),stat="identity") +
geom_point(data = new_df,aes(x=sorolog,y = record_id),colour = "#a81802",size = 4,shape = 1)
x = sorolog
中record_id
中的59个ID具有59个值。
但是当我运行它时,我得到了:
Error: Aesthetics must be either length 1 or the same as the data (59): fill
Run `rlang::last_error()` to see where the error occurred.
我认为这与融化的数据有冲突,因为它的长度是原始数据帧的两倍。
问题是:如何添加具有这种不同长度的点?
另一个问题:如何在剧情中添加第二个图例?
我使用了以下代码:
ggplot() +
geom_bar(data=t,fill=value),position=position_stack(reverse= FALSE),stat="identity",width = 0.5) +
scale_fill_manual(values = c("brown1","chocolate1"),name = "",labels = c("Hospitalization to Discharge","Symptom to Hospitalization")) +
geom_point(data = new_df,y = as.factor(record_id)),colour = "darkcyan",size = 5,shape = 1)+
geom_point(data = new_df,aes(x=final,colour = "darkred",shape = 16)+
theme_minimal()+
labs(title="Patient timeline - from symptoms to hospitalization and discharge",x ="Days",y = "Patient ID")+
theme(text = element_text(family = "Garamond",color = "grey20"))
但是我无法为geom_point元素添加图例,该怎么做?
编辑
通过Dave Armstrong的编辑,我得到了:
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)