본문 바로가기
반응형

범례4

[R ggplot2] 두 데이터를 하나의 산점도 그래프에 그릴 때 범례 및 색 설정 (x,y)로 대응되어 있는 데이터가 두 종류 있다고 합시다. data1=data.frame(x1=1:10,y1=dnorm(1:10)) data2=data.frame(x2=1:10,y2=dchisq(1:10,3)) 하나의 그래프에 두 데이터의 산점도를 그려봅시다. library(ggplot2) ggplot()+ geom_point(data=data1, aes(x=x1,y=y1))+ geom_point(data=data2, aes(x=x2,y=y2)) 범례를 설정해볼 것인데요. 여기서 많은 분들이 헷갈려하는 부분이 나옵니다. 아마 아래와 같이 색을 구분하려고 할 것입니다. ggplot()+ geom_point(data=data1, aes(x=x1,y=y1),color='red')+ geom_point(dat.. 2022. 5. 13.
[R ggplot2] 산점도 범례 생성 시 산점도 색 마음대로 설정하기 R 내장 데이터인 iris 데이터를 이용하겠습니다. > head(iris) Sepal.Length Sepal.Width Petal.Length Petal.Width Species 1 5.1 3.5 1.4 0.2 setosa 2 4.9 3.0 1.4 0.2 setosa 3 4.7 3.2 1.3 0.2 setosa 4 4.6 3.1 1.5 0.2 setosa 5 5.0 3.6 1.4 0.2 setosa 6 5.4 3.9 1.7 0.4 setosa 1. 색을 자동으로 구분하여 범례 생성 x값은 Sepal.Length 로 설정하고 y값은 Sepal.Width 로 설정하였습니다. 가장 기본적인 형태의 그래프를 그리고 범례를 설정합시다. 색은 Species 별로 구별되도록 했습니다. aes 안에 입력되는 color.. 2022. 5. 13.
[ R시각화] 바로 가져다 쓰는 범례(legend) 1. 범례를 색으로 구분 x 2020. 12. 30.
R 범례(legend) 넣는 방법 (위치,기호,색,크기) R 범례(legend) 넣는 방법 legend(x, y = NULL, legend, fill = NULL, col = par("col"), border = "black", lty, lwd, pch, angle = 45, density = NULL, bty = "o", bg = par("bg"), box.lwd = par("lwd"), box.lty = par("lty"), box.col = par("fg"), pt.bg = NA, cex = 1, pt.cex = cex, pt.lwd = lwd, xjust = 0, yjust = 1, x.intersp = 1, y.intersp = 1, adj = c(0, 0.5), text.width = NULL, text.col = par("col"), text.fo.. 2020. 6. 11.
반응형