code

ggplot에서 범례 제목 제거

codestyles 2020. 8. 19. 08:05
반응형

ggplot에서 범례 제목 제거


다음에서 범례 제목을 제거하려고합니다 ggplot2.

df <- data.frame(
  g = rep(letters[1:2], 5),
  x = rnorm(10),
  y = rnorm(10)
)

library(ggplot2)
ggplot(df, aes(x, y, colour=g)) +
  geom_line(stat="identity") + 
  theme(legend.position="bottom")

여기에 이미지 설명 입력

나는 이 질문을 보았고 거기에 어떤 해결책도 나를 위해 일하지 않는 것 같습니다. 대부분은 어떻게 optsdeprecated되고 theme대신 사용 하는지에 대한 오류를 제공합니다 . 나는 또한 다양한 버전을 시도했습니다 theme(legend.title=NULL), theme(legend.title=""), theme(legend.title=element_blank), 등 일반적인 오류 메시지는 다음과 같습니다

'opts' is deprecated. Use 'theme' instead. (Deprecated; last used in version 0.9.1)
'theme_blank' is deprecated. Use 'element_blank' instead. (Deprecated; last used in version 0.9.1)

ggplot20.9.3 버전이 출시 된 이후 처음으로 사용 하고 있으며 일부 변경 사항을 탐색하기가 어렵습니다.


거의 완료되었습니다. 추가하세요. theme(legend.title=element_blank())

ggplot(df, aes(x, y, colour=g)) +
  geom_line(stat="identity") + 
  theme(legend.position="bottom") +
  theme(legend.title=element_blank())

R 용 Cookbook의이 페이지에서는 범례를 사용자 지정하는 방법에 대한 자세한 내용을 제공합니다.


이것도 작동하며 범례 제목을 변경하는 방법도 보여줍니다.

ggplot(df, aes(x, y, colour=g)) +
  geom_line(stat="identity") + 
  theme(legend.position="bottom") +
  scale_color_discrete(name="")

들어 Error: 'opts' is deprecated. theme()대신 사용하십시오 . (소멸, 마지막 버전 0.9.1에서 사용) '나 교체 opts(title = "Boxplot - Candidate's Tweet Scores")와 함께 labs(title = "Boxplot - Candidate's Tweet Scores"). 작동했습니다!

참고 URL : https://stackoverflow.com/questions/14771546/remove-legend-title-in-ggplot

반응형