반응형
ggplot2 범례를 아래쪽 및 수평으로
ggplot2 범례를 플롯의 맨 아래로 이동하고 수평으로 돌리려면 어떻게해야합니까?
샘플 코드 :
library(reshape2) # for melt
df <- melt(outer(1:4, 1:4), varnames = c("X1", "X2"))
p1 <- ggplot(df, aes(X1, X2)) + geom_tile(aes(fill = value))
p1 + scale_fill_continuous(guide = guide_legend())
원하는 (대략적인) 결과 :
범례의 위치를 이동하려면 다음 코드를 사용하십시오.
library(reshape2) # for melt
df <- melt(outer(1:4, 1:4), varnames = c("X1", "X2"))
p1 <- ggplot(df, aes(X1, X2)) + geom_tile(aes(fill = value))
p1 + scale_fill_continuous(guide = guide_legend()) +
theme(legend.position="bottom")
원하는 결과를 얻을 수 있습니다.
요청한 내용을 정확히 제공하지는 않지만 매우 가까운 두 가지 불완전한 옵션 (적어도 색상을 조합 할 것임)
library(reshape2); library(tidyverse)
df <- melt(outer(1:4, 1:4), varnames = c("X1", "X2"))
p1 <- ggplot(df, aes(X1, X2)) + geom_tile(aes(fill = value))
p1 + scale_fill_continuous(guide = guide_legend()) +
theme(legend.position="bottom", legend.direction="vertical")
p1 + scale_fill_continuous(guide = "colorbar") + theme(legend.position="bottom")
2019-02-28에 reprex 패키지 (v0.2.1)로 생성됨
참고 URL : https://stackoverflow.com/questions/10032513/ggplot2-legend-to-bottom-and-horizontal
반응형
'IT박스' 카테고리의 다른 글
Ubuntu에서 구성 테스트가 성공한 후에 만 nginx를 다시 시작하려면 어떻게해야합니까? (0) | 2020.08.22 |
---|---|
모든 요인 수준에 대해 R 요인을 1/0 지표 변수 모음으로 자동 확장 (0) | 2020.08.22 |
innerHTML은 비동기식입니까? (0) | 2020.08.22 |
supervisorctl을 사용하여 특정 프로세스 만 다시 시작하는 방법은 무엇입니까? (0) | 2020.08.22 |
전환 애니메이션 중에 중첩 된 조각이 사라집니다. (0) | 2020.08.22 |