1
와 geom_errorbar이있을 때 선 색상을 변경 나는 다음과 같은 코드가 있습니다내가 ggplot
library(ggplot2)
library(gridExtra)
data = data.frame(fit = c(9.8,15.4,17.6,21.6,10.8), lower = c(7.15,12.75,14.95,18.95,8.15), upper = c(12.44,18.04,20.24,24.24,13.44), factors = c(15,20,25,30,35), var = rep("Fator", 5))
gp <- ggplot(data, aes(x=factors, y=fit, ymax=upper, ymin=lower))
gp <- gp + geom_line(aes(group=var),size=1.2) +
geom_errorbar(width=.8, size=1, aes(colour='red')) +
geom_point(size=4, shape=21, fill="grey") +
labs(x = paste("\n",data$var[1],sep=""), y =paste("Values","\n",sep="")) +
theme(legend.position = 'none', axis.text = element_text(size = 11), plot.margin=unit(c(0.4,0.4,0.4,0.4), "cm"), axis.text.x = element_text(angle=45, hjust = 1, vjust = 1)) +
ylim((min(data$lower)), (max(data$upper)))
나는 내가 ggplot 개체가 후 선 색상을 변경하고자합니다. 나는 노력하고있어 :
gp + scale_color_manual(values = "green")
그러나 오류 막대의 색이 바뀌고 선 색은 바뀌지 않습니다.
1) 선 색상을 변경하려면 어떻게해야합니까?
2) 포인트 색상은 어떻게 변경합니까?
감사합니다.
이것은 효과가있었습니다. 모든 일반 ggplot 객체의 색상과 모양을 편집 할 수있는 함수를 만들려고합니다. 이제는 객체의 레이어를 인식하고 매개 변수를 변경하는 방법이 필요합니다. 빠른 답변 주셔서 감사합니다. –
당신의 추론을 사용하는 다른 방법을 찾았습니다. 방금 수정했습니다 : gp $ layers [[1]] $ geom_params $ color = "green" 이렇게하면 초기 레이어에서 정보가 손실되지 않습니다. –