원 주위에 "감싸 인"텍스트를 쓸 수 있습니까? 나는 다음과 같은 것을 의미합니다 : 플롯에서 서클 주위에 텍스트 감싸기/굽힘
답변
또한 plotrix
패키지에 arctext
을 시도 할 수 있습니다 : 사용자 정의의 더 큰 기회를
library(plotrix)
# set up a plot with a circle
plot(x = 0, y = 0, xlim = c(-2, 2), ylim = c(-2, 2))
draw.circle(x = 0, y = 0, radius = 1)
# add text
arctext(x = "wrap some text", center = c(0, 0), radius = 1.1, middle = pi/2)
arctext(x = "counterclockwise", center = c(0, 0), radius = 1.1, middle = 5*pi/4,
clockwise = FALSE, cex = 1.5)
arctext(x = "smaller & stretched", center = c(0, 0), radius = 1.1, middle = 2*pi ,
cex = 0.8, stretch = 1.2)
(삼가, 좋은 삽화 참조), 당신이보고있을 수 있습니다 circlize
패키지에 있습니다. facing = "bending"
을 circos.text
에 설정하면 문자 주위가 원으로 둘러 쌉니다.
library(circlize)
# create some angles, labels and their corresponding factors
# which determine the sectors
deg <- seq(from = 0, to = 300, by = 60)
lab <- paste("some text", deg, "-", deg + 60)
factors <- factor(lab, levels = lab)
# initialize plot
circos.par(gap.degree = 10)
circos.initialize(factors = factors, xlim = c(0, 1))
circos.trackPlotRegion(ylim = c(0, 1))
# add text to each sector
lapply(factors, function(deg){
circos.updatePlotRegion(sector.index = deg, bg.col = "red")
circos.text(x = 0.5, y = 0.5, labels = as.character(deg), facing = "bending")
})
circos.clear()
업데이트
:circlize
version 0.2.1에서
circos.text
두 새로운 옵션 가지고
bending.inside
원래
bending
bending.outside
과 동일하다 (
the vignette에서도 11 참조). 따라서,
bending.outside
를 사용하여 플롯의 하단에 텍스트를 설정하는 쉬운 :
circos.par(gap.degree = 10)
circos.initialize(factors = factors, xlim = c(0, 1))
circos.trackPlotRegion(ylim = c(0, 1))
lapply(factors[1:3], function(deg){
circos.updatePlotRegion(sector.index = deg, bg.col = "red")
circos.text(x = 0.5, y = 0.5, labels = as.character(deg), facing = "bending.outside")
})
lapply(factors[4:6], function(deg){
circos.updatePlotRegion(sector.index = deg, bg.col = "red")
circos.text(x = 0.5, y = 0.5, labels = as.character(deg), facing = "bending.inside")
})
circos.clear()
예, 여기 코드는 무료입니다 :-). 나는이 글을 잠시 후에 썼지 만, 나는 어떤 CRAN 패키지에도 이것을 게시하지 않았다고 생각한다.
# Plot symbols oriented to local slope.
# Interesting problem: if underlying plot has some arbitrary aspect ratio,
# retrieve by doing: Josh O'B via SO:
# myasp <- with(par(),(pin[2]/pin[1])/(diff(usr[3:4])/diff(usr[1:2])))
# so make that the default value of argument 'asp'
# Default is 'plotx' is vector of indices at which to
# plot symbols. If is_indices=FALSE, only then turn to splinefun to
# calculate y-values and slopes; and user beware.
#
# 6 Feb 2014: added default col arg so can stick in a color vector if desired
# TODO
#
slopetext<-function(x,y,plotx, mytext, is_indices=TRUE, asp=with(par(), (pin[1]/pin[2])*(diff(usr[3:4])/diff(usr[1:2]))),offsetit= 0, col='black', ...) {
if (length(x) != length(y)) stop('data length mismatch')
if (!is.numeric(c(x,y,plotx))) stop('data not numeric')
if(is_indices) {
# plotting at existing points.
if(any(plotx<=1) | any(plotx>= length(x))) {
warning("can't plot endpoint; will remove")
plotx<-plotx[(plotx>1 & plotx<length(x))]
}
lows<-plotx-1
highs<-plotx+1
# then interpolate low[j],high[j] to get slope at x2[j]
slopes <- (y[highs]-y[lows])/(x[highs]-x[lows]) #local slopes
# sign(highlow) fix the rotation problem
angles <- 180/pi*atan(slopes/asp) + 180*(x[lows] > x[highs])
intcpts <- y[highs]-slopes*x[highs]
ploty <- intcpts + x[plotx]*slopes
# change name, so to speak, to simplify common plotting code
plotx<-x[plotx]
}else{
#interpolating at plotx values
if (any(plotx<min(x)) | any(plotx>max(x))) {
warning("can't plot extrapolated point; will remove")
plotx<-plotx[(plotx>min(x) & plotx<max(x))]
}
spf<-splinefun(x,y)
ploty<-spf(plotx)
angles <- 180/pi * atan(spf(plotx,1)/asp) #getting first deriv, i.e. slope
} #end of else
xlen<-length(plotx) # better match y and mytext
# The trouble is: srt rotates about some non-centered value in the text cell
# Dunno what to do about that.
dely <- offsetit*cos(angles)
delx <- offsetit*sin(angles)
# srt must be scalar
mytext<-rep(mytext,length=xlen)
col <- rep(col,length=xlen)
for (j in 1:xlen) text(plotx[j], ploty[j], labels=mytext[j], srt= angles[j], adj=c(delx,dely),col=col[j], ...)
}
편집 :
가x <- 1:100
y <- x/20 + sin(x/10)
plot(x,y,t='l')
slopetext(x=x,y=y,plotx=seq(10,70,by=10),mytext=letters[1:8])
이 예에서 세 번째 인수는 텍스트의 배치를위한 (X, Y)의 각 열 번째 값을 선택 데이비드의 우수한 제안 샘플 케이스 당. 나는 바보가 아니며, 극단적 인 경우에는 재미있는 방법으로 텍스트를 넣을 수 있다고 경고해야합니다.
아마 사용과 출력의 몇 가지 예제를 추가? upvote하기가 더 쉬울까요 :) –
@DavidArenburg는 결과를 게시 해 주셔서 감사합니다! –
- 1. OpenLayers3 서클 위의 텍스트 추가
- 2. 안드로이드 서클 안쪽에 텍스트 그리기
- 3. div 주위에 떠있는 텍스트
- 4. 텍스트 주위에 간격이 있습니다.
- 5. 텍스트 주위에 중괄호를 넣으시겠습니까?
- 6. 원 주위에 텍스트 그리기
- 7. 테두리 주위에 텍스트 범위
- 8. UIImageView 주위에 텍스트 감싸기
- 9. 격자 플롯에서 스트립의 텍스트 변경
- 10. 목표 C 서클 서클 경고
- 11. d3js 특정 텍스트 라벨이있는 서클 선택
- 12. CSS-div 주위에 떠있는 텍스트
- 13. 고정 디바이더 주위에 텍스트 감싸기
- 14. div 주위에 텍스트 줄 바꾸기
- 15. CSS를 사용하여 텍스트 주위에 테두리
- 16. QPrinter 이미지 주위에 텍스트 배치
- 17. 링크 텍스트 주위에 jQuery로 감싸기
- 18. Matlab 플롯에서 텍스트 상자의 위치를 지정하십시오.
- 19. 한 플롯에서 두 개의 텍스트 플롯
- 20. 플롯에서 hover 텍스트 bg를 흰색으로 설정
- 21. 확인란이있는 마커에 서클 오버레이 추가
- 22. 서클 애니메이션
- 23. 서페이스지도에 서클 그리기 Matlab
- 24. CSS 하이퍼 링크를 둘러싼 서클
- 25. 정규식을 사용하여 텍스트 블록 주위에 무언가 넣기
- 26. SQL 검색 : 검색어 주위에 텍스트 만 표시
- 27. 이미지 과수원 주위에 간단한 감싸기 텍스트 CMS
- 28. WP8의 이미지 주위에 텍스트 감기 XAML
- 29. 정확히 텍스트 주위에 간격을 지정하는 방법
- 30. 라텍스의 아주 작은 이미지 주위에 텍스트 감싸기
'circlize' 편집이 머리에 못을 박 았기 때문에 나는 이것을 두 번 upvote 할 수 있었으면 좋겠습니다. –
감사합니다. @RichardScriven. 'circlize'는 참으로 멋진 패키지입니다. 저자는 비 네트로 놀라운 일을했습니다. 건배. – Henrik
나는 이것을 잠시 보지 못했지만, 일반적인 곡선 (내 대답의 '죄'예처럼)으로는 작동하지 않는다는 점을 고쳐 줍니까? –