size to linewidth, ggplot2 upgrade not working for text in annotate()

87 views Asked by At

EDIT/UPDATE: Solved. See comments for answer.
Original Below Line_________________________________________________________________
Two questions, first, I'm trying to upgrade my ggplot2 plotting code to use linewidth instead of size to display text with annotate() and second I'm using get('') workaround for R CMD's check() as I develop my package, but people don't seem to think it's a good idea, so I want a second opinion.
Q1.
Currently, when I run this code:

covarianceGraph<-dagitty::dagitty("dag {
  t1.0
  t1.3
  t2.0
  t3.0
  t4.0
  t4.3
  t1.0 -> t2.0 [beta=\"0.12\"]
  t1.0 -> t3.0 [beta=\"0.13\"]
  t1.0 -> t4.0 [beta=\"0.14\"]
  t1.3 <-> t4.3 [beta=\"0.41\"]
  t2.0 -> t4.3 [beta=\"0.24\"]
  t3.0 -> t4.0 [beta=\"0.34\"]
}")
g<-SEMgraph::dagitty2graph(covarianceGraph)
x_reordered<-c(1,2,3,1,4,4);  y_reordered<-c(0,0,0,3,3,0)
g_vertex_coords<-matrix(c(x_reordered,y_reordered),byrow=FALSE,ncol=2)
x_range<-3;  x_center<-2.5;  xAxisYIntercept<- -0.272727272727273
xLAbelYIntercept<- -0.428571428571429;  yLineXIntercept<-0.75
yLabelsXIntercept<-0.666666666666667;  ytitleXIntercept<-0.4
titleYIntercept<-3.78;  titleXIntercept<-0.0322580645161291
yLabels<-c("0-","1-","2-","3-")
yMax<-3;  yMin<-0;  y_range<- yMax-yMin;  y_center<-y_range/2
yStart<-ceiling(yMin);  yEnd<-floor(yMax)
edgeLabels<-c("0.12","0.13","0.14","0.24","0.34","0.41","")
Curv<-c(0.2,0.2,0.2,0.2,0.2,0.3,-0.3)
varianceVector<-c(t1=2,t2=1,t3=1,t4=2)
print((ggraph::ggraph(g, layout = 'manual', x = g_vertex_coords[,1], y = g_vertex_coords[,2]) +
         ggraph::geom_edge_arc(ggplot2::aes(label = edgeLabels),
                   strength = Curv,
                   arrow = ggplot2::arrow(angle = 30, length = ggplot2::unit(3, 'mm'),
                                          type = 'closed'), end_cap = ggraph::circle(7, 'mm'),
                   start_cap = ggraph::circle(7, 'mm'),
                   color = 'gray50',
                   label_dodge = ggplot2::unit(2, 'mm'), vjust = -1) +
         ggraph::geom_node_circle(ggplot2::aes(r = 0.15), fill = '#ffe0a0', color = 'orange4') +
         ggraph::geom_node_text(ggplot2::aes(label=get('name'))) +
         ggplot2::coord_equal() +
         # title
         ggplot2::annotate("text", x=titleXIntercept, y=titleYIntercept, label ="Relationships",size=7,hjust=0) +
         # Y Axis
         ggplot2::annotate("text", x=ytitleXIntercept, y=y_center, label ="Total Temporal Delay",size=6,angle = 90) +
         ggplot2::annotate("segment", x = yLineXIntercept, xend = yLineXIntercept, y = yMin, yend = yMax, color="black")+
         ggplot2::annotate("text", x = yLabelsXIntercept, y = yStart:yEnd, label = yLabels,size=6) +
         # X Axis
         ggplot2::annotate("text", x = 1:length(varianceVector), y = xAxisYIntercept, label = names(varianceVector)) +
         ggplot2::annotate("text", x=x_center,y=xLAbelYIntercept,label="Traits", size=6) +
         ggraph::theme_graph(plot_margin = ggplot2::margin(0, 0, 0, 0))))

I get

Using the `size` aesthetic in this geom was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` in the `default_aes` field and elsewhere instead.
This warning is displayed once every 8 hours.
Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated. 

And when I run check(), I get:

 ══ Warnings ════════════════════════════════════════════════════════════════════
── Warning ('test-plotCovarianceGraph.R:14:3'): Must manually test graph inspection ──
Using the `size` aesthetic in this geom was deprecated in ggplot2 3.4.0.
i Please use `linewidth` in the `default_aes` field and elsewhere instead.
Backtrace:
     ▆
  1. ├─testthat::expect_silent(plotCovarianceGraph(d, v)) at test-plotCovarianceGraph.R:14:2
  2. │ └─testthat:::quasi_capture(enquo(object), NULL, evaluate_promise)
  3. │   ├─testthat (local) .capture(...)
  4. │   │ ├─withr::with_output_sink(...)
  5. │   │ │ └─base::force(code)
  6. │   │ ├─base::withCallingHandlers(...)
  7. │   │ └─base::withVisible(code)
  8. │   └─rlang::eval_bare(quo_get_expr(.quo), quo_get_env(.quo))
  9. └─physh:::plotCovarianceGraph(d, v)
 10.   ├─base::print(...)
 11.   └─ggplot2:::print.ggplot(...)
 12.     ├─ggplot2::ggplot_build(x)
 13.     ├─ggraph:::ggplot_build.ggraph(x)
 14.     ├─base::NextMethod()
 15.     └─ggplot2:::ggplot_build.ggplot(x)
 16.       └─ggplot2:::by_layer(...)
 17.         ├─rlang::try_fetch(...)
 18.         │ ├─base::tryCatch(...)
 19.         │ │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
 20.         │ │   └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
 21.         │ │     └─base (local) doTryCatch(return(expr), name, parentenv, handler)
 22.         │ └─base::withCallingHandlers(...)
 23.         └─ggplot2 (local) f(l = layers[[i]], d = data[[i]])
 24.           └─l$compute_geom_2(d)
 25.             └─ggplot2 (local) compute_geom_2(..., self = self)
 26.               └─self$geom$use_defaults(data, self$aes_params, modifiers)
 27.                 └─ggplot2 (local) use_defaults(..., self = self)
 28.                   └─ggplot2:::deprecate_soft0(...)



Q 2.
I was getting this error: How can I handle R CMD check "no visible binding for global variable" notes when my ggplot2 syntax is sensible? And it seems to be the answer at the very bottom with only a single upvote is the best solution, just use get(''). But I'm suspicious that there's something wrong with it since it isn't upvoted, so any advice on that would be great. thank you. Specifically, I'm already using it in the code above.

Q 1.
I have tried every single possible combination of using aes, default_aes, etc. that i could imagine in all locations, inside annotate(), outside annotate(), I even tried not using any of them, and just replacing the word size with linewidth in my code, but I always get one type of error or another. Just as a quick example, when I replace size with linewidth ggplot2::annotate("text", x=titleXIntercept, y=titleYIntercept, label ="Relationships",linewidth=7,hjust=0) + I get

Warning message:
In ggplot2::annotate("text", x = titleXIntercept, y = titleYIntercept,  :
  Ignoring unknown parameters: `linewidth`

And I don't remember all the other errors I got playing around with aes commands, but i think default_aes for example was also 'unknown'

Q 2.
I tried get() and it worked.

0

There are 0 answers