嘿,大家我希望有人在那裏可以幫我繪製一個定製的P在R在我的情況下,我試圖創建一個關於水質的圖形隨着時間的推移。監測水質的一種方法是使用secchi光盤,該光盤基本上是一個金屬圓盤,黑色和白色圓盤的四分之一(參見下圖)。自動調整自定義繪圖角色的大小?
到目前爲止,我已經能夠成功創建光盤並將其放置在情節中,但是根據情節的尺寸,我的問題伴隨着拉伸效果。
下面是我用創建至今光盤的功能:
# A circle function to draw a circle (pulled form another stackoverflow page)
circleFun <- function(center=c(0,0), diameter=1, npoints=100, start=0, end=2, filled=TRUE){
tt <- seq(start*pi, end*pi, length.out=npoints)
df <- data.frame(
x = center[1] + diameter/2 * cos(tt),
y = center[2] + diameter/2 * sin(tt)
)
if(filled==TRUE) { #add a point at the center so the whole 'pie slice' is filled
df <- rbind(df, center)
}
return(df)
}
# and my function to create a secchi disc
secchiDisc = function(x,y,diameter = 1){
quarterCircle1 = circleFun(c(x,y),diameter = diameter, start=0, end=0.5)
quarterCircle3 = circleFun(c(x,y),diameter = diameter, start=1, end=1.5)
fullCircle = circleFun(c(x, y), diameter, start=0, end=2)
polygon(quarterCircle1$x,quarterCircle1$y,col="black")
polygon(quarterCircle3$x,quarterCircle3$y,col="black")
polygon(fullCircle$x,fullCircle$y)
}
# make a plot to show what it looks like
par(mar = c(5, 4, 4, 2) + 0.1)
plot(0,0,pch = "")
secchiDisc(0,0)
# create data frame
data = as.data.frame(list(Year = 1970:2015,
Depth = rnorm(46,3,1)))
# and create a time series plot showing changes in depth over time
plot(data$Year,data$Depth,pch="",ylim = c(7,0))
for(i in 1:nrow(data)){
secchiDisc(data$Year[i],data$Depth[i])
}
A很明顯,我可以水平拉伸繪圖直到清理完成,但是我想知道有沒有人對如何根據情節自動讓光盤重新調整大小有任何建議?
我試過自定義圓圈函數以允許拉伸效果,但無濟於事。我認爲「拉伸效應」方法存在的一個問題是,我仍然希望光盤呈圓形,但我無法獲得圓的直徑以獨立於x或y維度進行更改。
我的另一個想法是將secchi光盤的空白圖保存爲png文件並嘗試繪製導入的文件。關於這種方法的想法?
感謝您的任何幫助。
這看起來太棒了。非常感謝你的幫助。 – anotherFishGuy