ggplot
다음 코드를 사용하여 생성 된 플롯이 주어지면
size = 10000
d = data.frame(
type = rep(c("A","B","C"), each=size),
val = c(rnorm(size, 0, 1), rnorm(size, 1, 2),rnorm(size, 2, 3))
)
require(ggplot2)
(
ggplot(subset(d, is.element(type, c("A", "C"))), aes(x=val))
+ geom_histogram(aes(y=..density..), bins=100, position="identity", alpha=0.5)
+ geom_line(aes(color=type), stat="density", size=1)
)
간단한 히스토그램을 나타내는 사용자 지정 레이블이있는 회색 사각형을 범례에 추가 할 수 있습니까? 더미 항목 을 만들지 않고도 할 수 있습니까 ?
당신이 필요 fill=
로 aes()
하는 것은 geom_histogram()
라인 에 넣는 것 입니다 . 이에 할당 할 데이터 집합의 열이없는,하지만 당신은 할당하는 경우 fill="string name"
에 aes()
, 다음 ggplot
의 레이블과 그와 채우기 범례를 작성합니다.
물론 색상은 기본적으로 ggplot
"빨간색"색상으로 설정되므로 다시 회색으로 설정하려면으로 설정해야합니다. 외부 는 안에 넣은 모든 것을 덮어 쓰기 scale_fill_manual()
때문 입니다.fill=
aes()
aes()
ggplot(d, aes(x=val)) +
geom_histogram(aes(y=..density.., fill='histogram'),
bins=100, position="identity", alpha=0.5) +
geom_line(aes(color=type), stat="density", size=1) +
scale_fill_manual(values='gray20')
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다