이 시도 :
1) 색상 레드 75 점을 넘어 모든 Y 값
SecondPlot <- ggplot(sur11, aes(x=standec, y=compnoanti)) +
geom_point(col = ifelse(sur11$compnoanti > 75, "red", "black"), size = 0.5) +
geom_text(label=sur11$concatena, hjust = 0, nudge_x = 0.3, size = 2.5)
SecondPlot
2) 조정 색상을 소개 나는 색상으로, 기존 R의 맥주 규모, 예를 들어, "블루스"를 사용하도록 Y 값은 값에 따라 다릅니 까?
#Interpolate Brewer palette
library(RColorBrewer)
colourCount = length(unique(sur11$compnoanti))
getPalette = colorRampPalette(brewer.pal(9, "Blues"))
SecondPlot <- ggplot(mtcars, aes(x=standec, y=compnoanti)) +
geom_point(aes(col = compnoanti), size = 0.5) +
geom_text(label=sur11$concatena, hjust = 0, nudge_x = 0.3, size = 2.5) +
scale_colour_gradientn(colours=getPalette(colourCount))
SecondPlot
재현 가능한 예제를 제공하지 않아 일반 데이터 세트를 사용하여 테스트했습니다. 이것은 일반적인 버전입니다 :
# Color points above a certain value red
SecondPlot <- ggplot(mtcars, aes(x=mpg, y=disp)) +
geom_point(col = ifelse(mtcars$disp > 120, "red", "black"), size = 0.5) +
geom_text(label=rownames(mtcars), hjust = 0, nudge_x = 0.3, size = 2.5)
SecondPlot
#Interpolate Brewer palette
library(RColorBrewer)
colourCount = length(unique(mtcars$disp))
getPalette = colorRampPalette(brewer.pal(9, "Blues"))
SecondPlot <- ggplot(mtcars, aes(x=mpg, y=disp)) +
geom_point(aes(col = disp), size = 0.5) +
geom_text(label=rownames(mtcars), hjust = 0, nudge_x = 0.3, size = 2.5) +
scale_colour_gradientn(colours=getPalette(colourCount))
SecondPlot
대단히 감사합니다. 한 가지 질문 - 레이블뿐만 아니라 점의 색을 원하면 어떻게 할 수 있습니까? 감사합니다 @HAVB –
@HenryCann은'gees_text' 라인에'aes (color = whateverVariable)'를 추가합니다. 예를 보려면 여기를 확인하십시오. http://docs.ggplot2.org/current/geom_text.html – HAVB
감사합니다. 레이블에 색상을 추가 할 수 있었지만 스케일이 아닌 색상을 추가 할 수 있었습니까? geom_text에 scale_colour_gradient 인수를 인수로 추가 할 수 있습니까? 건배 @HAVB –