gpt4 book ai didi

r - 当应该有两条线出现在我的图上

转载 作者:行者123 更新时间:2023-12-04 12:35:23 26 4
gpt4 key购买 nike

我正在ggplot中绘制图,当我添加geom_line()层时,它包括2条线而不是一条。谁能帮助我了解它为什么这样做?

码:

library(ggplot2)
a <- data.frame(SubjectId=c(1:3, 1:3, 1:3, 1:3),
Cycle=c(1,1.1,1.2, 2,2.1,2.2, 3,3.1,3.2, 4,4.1,4.2),
Dose=c(sort(rep(1:3,3)), 3,3,3),
DLT=c("No","No","Yes","No","No","No","No","Yes","Yes","No","Yes","Yes"))


ggplot(aes(x=Cycle, y=Dose, fill=DLT), data = a) +
scale_fill_manual(values = c("white", "black")) +
geom_line(colour="grey20", size=1) +
geom_point(shape=21, size=5) +
xlim(1, 4.5) +
ylim(1, 4) +
ylab("Dose Level") +
theme_classic() +
theme(axis.text =element_text(size=10),
axis.title =element_text(size=12, face="bold", colour="grey20"),
legend.text =element_text(size=10),
legend.title=element_text(size=12, face="bold", colour="grey20"))


我只希望一条线按Cycle的顺序经过点,但是按Cycle排序根本不会改变这条线。我究竟做错了什么?

最佳答案

fill=DLT放在geom_point()部分中,而不是放在顶部。例如:

 ggplot(aes(x=Cycle, y=Dose), data = a) +
scale_fill_manual(values = c("white", "darkred")) +
geom_line(colour="grey20", size=1) +
geom_point(shape=23, size=5, aes(fill=DLT)) +
xlim(1, 4.5) +
ylim(1, 4) +
ylab("Dose Level") +
theme_classic() +
theme(axis.text =element_text(size=10),
axis.title =element_text(size=12, face="bold", colour="grey20"),
legend.text =element_text(size=10),
legend.title=element_text(size=12, face="bold", colour="grey20"))

关于r - 当应该有两条线出现在我的图上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53404278/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com