R의 플롯에서 글꼴 크기를 늘리는 방법은 무엇입니까?
혼란 스러워요. 제목, 레이블 및 줄거리의 다른 위치에서 텍스트의 글꼴 크기를 늘리는 올바른 방법은 무엇입니까?
예를 들어
x <- rnorm(100)
hist(x, xlim=range(x), xlab= "Variable Label",
ylab="density", main="Title of plot", prob=TRUE, ps=30)
ps
인수는 글꼴 크기를 변경하지 않습니다 (하지만위한 R 도움말에서 말한다 ?par
는 "텍스트 (그러나 심볼)의 포인트 크기"에 대한 것을.
또한 hist
? 와 같은 플로팅 기능에서 글꼴 크기 변경을 분리 할 수 있습니다 .
cex=1.5
글꼴 크기를 150 %로 조정 하는 인수 와 같은 것을 원합니다 . 그러나 보는가 help(par)
도 있기 때문에 cex.lab
, cex.axis
...
따라서 기존 토론을 요약하려면
cex.lab=1.5, cex.axis=1.5, cex.main=1.5, cex.sub=1.5
플롯에 1.5가 2, 3 등이 될 수 있으며 1이 기본값이면 글꼴 크기가 증가합니다.
x <- rnorm(100)
cex는 변경하지 않습니다
hist(x, xlim=range(x),
xlab= "Variable Lable", ylab="density", main="Title of plot", prob=TRUE)
hist(x, xlim=range(x),
xlab= "Variable Lable", ylab="density", main="Title of plot", prob=TRUE,
cex=1.5)
cex.lab = 1.5, cex.axis = 1.5, cex.main = 1.5, cex.sub = 1.5를 추가하십시오.
hist(x, xlim=range(x),
xlab= "Variable Lable", ylab="density", main="Title of plot", prob=TRUE,
cex.lab=1.5, cex.axis=1.5, cex.main=1.5, cex.sub=1.5)
Notice that "cex" does change things when the plot is made with text. For example, the plot of an agglomerative hierarchical clustering:
library(cluster)
data(votes.repub)
agn1 <- agnes(votes.repub, metric = "manhattan", stand = TRUE)
plot(agn1, which.plots=2)
will produce a plot with normal sized text:
and plot(agn1, which.plots=2, cex=0.5)
will produce this one:
By trial and error, I've determined the following is required to set font size:
cex
doesn't work inhist()
. Usecex.axis
for the numbers on the axes,cex.lab
for the labels.cex
doesn't work inaxis()
either. Usecex.axis
for the numbers on the axes.- In place of setting labels using
hist()
, you can set them usingmtext()
. You can set the font size usingcex
, but using a value of 1 actually sets the font to 1.5 times the default!!! You need to usecex=2/3
to get the default font size. At the very least, this is the case under R 3.0.2 for Mac OS X, using PDF output. - You can change the default font size for PDF output using
pointsize
inpdf()
.
I suppose it would be far too logical to expect R to (a) actually do what its documentation says it should do, (b) behave in an expected fashion.
I came across this when I wanted to make the axis labels smaller, but leave everything else the same size. The command that worked for me, was to put:
par(cex.axis=0.5)
Before the plot command. Just remember to put:
par(cex.axis=1.0)
플롯 후 글꼴이 기본 크기로 돌아가는지 확인하십시오.
labels = TRUE를 설정할 때 히스토그램 레이블의 글꼴을 늘리려는 경우
bp=hist(values, labels = FALSE,
main='Histogram',
xlab='xlab',ylab='ylab', cex.main=2, cex.lab=2,cex.axis=2)
text(x=bp$mids, y=bp$counts, labels=bp$counts ,cex=2,pos=3)
완성도를 높이고를 사용하여 텍스트 크기를 150 % 조정 cex = 1.5
하는 방법은 다음과 같습니다.
cex <- 1.5
par(cex.lab=cex, cex.axis=cex, cex.main=cex)
plot(...)
par(cex.lab=1, cex.axis=1, cex.main=1)
상용구를 줄이기 위해 이와 같은 것을 포장하는 것이 좋습니다. 예 :
plot_cex <- function(x, y, cex=1.5, ...) {
par(cex.lab=cex, cex.axis=cex, cex.main=cex)
plot(x, y, ...)
par(cex.lab=1, cex.axis=1, cex.main=1)
invisible(0)
}
다음과 같이 사용할 수 있습니다.
plot_cex(x=1:5, y=rnorm(5), cex=1.3)
는 ...
R에서 타원으로 공지되어 있으며, 기능에 추가 파라미터를 전달하는 데 사용된다. 따라서 일반적으로 플로팅에 사용됩니다. 따라서 다음과 같이 작동합니다.
plot_cex(x=1:5, y=rnorm(5), cex=1.5, ylim=c(-0.5,0.5))
참고 URL : https://stackoverflow.com/questions/4241798/how-to-increase-font-size-in-a-plot-in-r
'IT' 카테고리의 다른 글
Eclipse가 "JNI 공유 라이브러리를로드하지 못했습니다"라고보고 함 (0) | 2020.07.01 |
---|---|
구아바 라이브러리 : 가장 유용하고 숨겨진 기능은 무엇입니까? (0) | 2020.07.01 |
사전을 해싱? (0) | 2020.07.01 |
반복 불가능한 읽기와 팬텀 읽기의 차이점은 무엇입니까? (0) | 2020.07.01 |
BestPractice-문자열의 첫 문자를 소문자로 변환 (0) | 2020.07.01 |