控制ggplot2中的箭头形状

时间:2015-05-21 23:00:06

标签: r ggplot2 plot

我正在制作一个图形,在中心周围绘制一系列箭头,有点像自行车轮胎轮,但箭头指向内部。箭头数量等输入都通过一个闪亮的应用程序控制,该应用程序调用我的绘图功能如下:

FPlot1<-function(arr.dat,var_explained){
  g<-rasterGrob(img,interpolate=TRUE)
  plot.grid<-ggplot(data=arr.dat,aes(colour=val))+scale_colour_gradient2(low="blue",mid="purple",high="red",midpoint=0,guide="colourbar")+theme_bw()#+coord_fixed()# +facet_grid(pc ~.)
  plot.grid<-plot.grid+
    scale_x_continuous(name="",limits=c(-7,7))+
    scale_y_continuous(name="",limits=c(-7,7))+
    geom_segment(data=arr.dat, aes(x=x2,y=y2,xend=x1,yend=y1,size=abs(val)*4),arrow=arrow(length=unit(.5,"cm")))+
    geom_text(data=arr.dat,aes(x=center+6*cos(angle), y=center+5.3*sin(angle),label=row),colour="black",size=3)+
    annotation_custom(g,xmin=-1,ymin=-1,xmax=1,ymax=1)+
    geom_text(data=arr.dat,aes(x=center,y=center,label=pc),colour="black",size=4,fontface="bold",family="Times")+
    geom_text(data=arr.dat,aes(x=xmid,y=ymid,hjust=1,vjust=1,angle=(txtangle*180/pi),label=val),colour="black",size=4)+
    theme(line=element_blank(),text=element_blank(),line=element_blank())
  return(plot.grid)

}

我遇到的关键问题是当箭头变大时箭头看起来很糟糕,如下左箭头所示。我一直在寻找是否有控制箭头的ggplot,但没有运气。我宁愿留在ggplot,因为有一个数据框控制我的情节的所有部分是方便的,但如果我需要切换我明白!

提前感谢您的帮助!

快速截图。

enter image description here

传入上述功能的数据框

structure(list(row = structure(c(3L, 1L, 2L), .Label = c("actualdisplacement", 
"LHPA_wk1", "STD_TissDeform"), class = "factor"), x1 = c(-0.75, 
-0.750000000000001, 1.5), y1 = c(1.29903810567666, -1.29903810567666, 
-3.67394039744206e-16), x2 = c(-2.5, -2.5, 5), y2 = c(4.33012701892219, 
-4.33012701892219, -1.22464679914735e-15), val = c(0.914, 0.371, 
0.068), center = c(0, 0, 0), angle = c(2.0943951023932, 4.18879020478639, 
6.28318530717959), pc = structure(c(1L, 1L, 1L), .Label = "PC1", class = "factor"), 
    xmid = c(-1.625, -1.625, 3.25), ymid = c(2.81458256229943, 
    -2.81458256229942, -7.9602041944578e-16), txtangle = c(-1.0471975511966, 
    1.0471975511966, 6.28318530717959), stringAsFactors = c(1, 
    1, 1)), .Names = c("row", "x1", "y1", "x2", "y2", "val", 
"center", "angle", "pc", "xmid", "ymid", "txtangle", "stringAsFactors"
), row.names = c(NA, -3L), class = "data.frame")

0 个答案:

没有答案