반응형
미학과 geom_text를 사용할 때 범례에서 'a'제거
이 코드로 생성 된 범례에서 문자 'a'를 제거하려면 어떻게해야합니까? 를 제거하면 geom_text
'a'문자가 범례에 표시되지 않습니다. geom_text
그래도 유지하고 싶습니다 .
ggplot(data = iris, aes(x = Sepal.Length, y=Sepal.Width, shape = Species, colour = Species)) +
geom_point() +
geom_text(aes(label = Species))
설정 show.legend = FALSE
에서 geom_text
:
ggplot(data = iris,
aes(x = Sepal.Length, y = Sepal.Width, colour = Species, shape = Species, label = Species)) +
geom_point() +
geom_text(show.legend = FALSE)
인수의 show_guide
이름이 show.legend
in으로 변경 되었습니다 ggplot2 2.0.0
( 릴리스 뉴스 참조 ).
사전 ggplot2 2.0.0
:
와 show_guide = FALSE
같은 ...
ggplot( data=iris, aes(x=Sepal.Length, y=Sepal.Width , colour = Species , shape = Species, label = Species ) , size=20 ) +
geom_point()+
geom_text( show_guide = F )
비슷한 문제 가있었습니다 . Simon의 솔루션은 나를 위해 일했지만 약간의 비틀기가 필요했습니다. 나는 geom_text의 인수 에 "show_guide = F" 를 추가 해야한다는 것을 깨닫지 못했습니다 . 기존 인수로 대체하는 것이 아니라 Simon의 솔루션이 보여주는 것입니다. 나 같은 ggplot2 멍청한 사람에게는 이것은 그렇게 분명하지 않았습니다. 적절한 예는 OP의 코드를 사용하고 다음과 같이 누락 된 인수를 추가했을 것입니다.
..
geom_text(aes(label=Species), show_guide = F) +
..
Nick이 말한 것처럼
다음 코드는 여전히 오류를 생성합니다.
geom_text(aes(x=1,y=2,label="",show_guide=F))
이므로:
geom_text(aes(x=1,y=2,label=""),show_guide=F)
aes 인수 외부에서는 범례에 대한 a를 제거합니다.
guide_legend(override.aes = aes(...))
범례에서 'a'를 숨기는 데 사용할 수 있습니다 .
아래는 guide_legend () 사용 방법에 대한 간단한 예입니다.
library(ggrepel)
#> Loading required package: ggplot2
d <- mtcars[c(1:8),]
p <- ggplot(d, aes(wt, mpg)) +
geom_point() +
theme_classic(base_size = 18) +
geom_label_repel(
aes(label = rownames(d), fill = factor(cyl)),
size = 5, color = "white"
)
# Let's see what the default legend looks like.
p
# Now let's override some of the aesthetics:
p + guides(
fill = guide_legend(
title = "Legend Title",
override.aes = aes(label = "")
)
)
2019-04-29에 reprex 패키지 (v0.2.1)에 의해 생성됨
반응형
'programing tip' 카테고리의 다른 글
AngularJS의 여러 특정 모델 속성으로 필터링 (OR 관계) (0) | 2020.08.11 |
---|---|
Pandas로 txt에서 데이터로드 (0) | 2020.08.11 |
파이썬의 클래스 상수 (0) | 2020.08.10 |
내부 클래스가 개인 변수에 액세스 할 수 있습니까? (0) | 2020.08.10 |
magento의 캐시 관리에서 "Flush Magento Cache"와 "Flush Cache Storage"의 차이점은 무엇입니까? (0) | 2020.08.10 |