ggplot2에 다시 문제가 생겼습니다.
두 가지 다른 색상과 두 가지 다른 모양으로 최소 두 개의 데이터 세트를 플로팅하고 싶습니다. 이것은 작동하지만 범례의 이름을 넣으려고하면 자동으로 범례가 두 배가됩니다. 데이터 세트의 수는 물론 범례 이름도 변경 될 수 있습니다. 이 예제에서 작동하지 않는 코드가 필요합니다.
library(ggplot2)
xdata=1:5
ydata=c(3.45,4.67,7.8,8.98,10)
ydata2=c(12.4,13.5,14.6,15.8,16)
p <-data.frame(matrix(NA,nrow=5,ncol=3))
p$X1 <- xdata
p$X2 <- ydata
p$X3 <- ydata2
shps <-c(1,2)
colp <-c("navy","red3")
p <- melt(p,id="X1")
px <-ggplot(p,aes(X1,value))
legendnames <- c("name1","name2")
px <- px +aes(shape = factor(variable))+
geom_point(aes(colour =factor(variable)))+
theme_bw()+
scale_shape_manual(labels=legendnames,values =shps )+
scale_color_manual(values = colp)
px
이것은 나에게 이것을 준다 :
하지만 내 전설 이름으로 원해
방금 labels=legendnames,
scale_shape_manual을 삭제했습니다 .
그래서 그 문제를 해결하는 문제는 무엇입니까. 도와주세요
나는 이것이 동일한 labels
매개 변수를 에 제공하는 문제라고 생각 합니다 scale_color_manual
. 그렇지 않으면 범례를 통합하는 방법을 모릅니다.
그래서
px <- px + aes(shape = factor(variable)) +
geom_point(aes(colour = factor(variable))) +
theme_bw()+
scale_shape_manual(labels=legendnames, values = shps)+
scale_color_manual(labels=legendnames, values = colp)
px
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다