How can I pass individual `curvature` arguments in `ggplot2` `geom_curve` function?

前端 未结 2 1525
予麋鹿
予麋鹿 2020-12-11 04:26

I have a df with two curve definitions, each consists of two points and a curvature value. The goal is to plot two individual curves using ggplot2

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-11 04:42

    You could use a for loop to build up your ggplot call as a text string and evaluate the string once the for loop finishes.

    graphString <- "ggplot(df) "
    for(i in 1:nrow(df)){
      newCurve <- paste(" + geom_curve(data = df[",i,", ], aes(x = x, y = y, xend = xend, yend = yend), curvature = df$curvature[",i,"])", sep="")
      graphString <- paste(graphString, newCurve,sep="")
    }
    
    eval(parse(text = graphString))
    

提交回复
热议问题