에서 키 레이블을 변경 ggplot
하려고했지만 실패했습니다. scale_color_manual
줄에 레이블을 표시하면 범례가 중복 된 것처럼 보입니다. 내 실수는 어디에 있습니까?
예를 고려하십시오.
mydata <- data.frame(
year=as.integer(rep(2010:2020,each=2)),
type=rep(c("a","b"),11),
value=c(617,186,546,241,430,217,349,188,286,141,446,166,442,167,424,210,421,182,405,190,432,194))
ggplot(mydata,aes(year,value,group=type))+
theme_bw()+
theme(
axis.text=element_text(size=16),
axis.title=element_text(size=18),
legend.position=c(.75,.885),
legend.key = element_rect(color = "white", fill = NA),
legend.key.size = unit(1, "cm"),
legend.title=element_blank(),
legend.text=element_text(size=20)
)+
labs(x="year",y="number")+
geom_point(aes(color=type,shape=type),size=3)+
scale_x_continuous(breaks = seq(min(mydata$year),max(mydata$year), by = 2))+
scale_shape_manual(values=c(15,19))+
scale_color_manual(values=c("red","blue"))
하지만 범례 키 "a"와 "b"를 "group a"로, "group b"를
scale_color_manual(values=c("red","blue"),labels=c("group a","group b"))
중복 된 범례가 나타나고 색이 지정된 총알이 잘못됩니다.
무슨 일이야?
감사!
색상 및 모양 척도에 동일한 레이블을 추가하는 경우 요인 수준을 변경하지 않고도이 작업을 수행 할 수 있습니다.
ggplot(mydata,aes(year,value,group=type))+
theme_bw()+
theme(
axis.text=element_text(size=16),
axis.title=element_text(size=18),
legend.position=c(.75,.885),
legend.key = element_rect(color = "white", fill = NA),
legend.key.size = unit(1, "cm"),
legend.title=element_blank(),
legend.text=element_text(size=20)
)+
labs(x="year",y="number")+
geom_point(aes(color=type,shape=type),size=3)+
scale_x_continuous(breaks = seq(min(mydata$year),max(mydata$year), by = 2))+
scale_shape_manual(values=c(15,19), labels = c("group a", "group b")) +
scale_color_manual(values=c("red","blue"), labels = c("group a", "group b"))
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다