Stop parsing out zeros after decimals in ggplot2's annotate

前端 未结 1 1360
温柔的废话
温柔的废话 2021-01-13 11:44

I need to annotate a location on a ggplot2 plot with a line that contains both a (real) greek letter and a number rounded to 2 decimal places. My problem arises because I wa

1条回答
  •  生来不讨喜
    2021-01-13 12:21

    You can do it with the use of deparse.

    So your code looks like this

    alpha_num <- "1.00"
    p <- ggplot(data.frame(x=1,y=1,label=paste0("alpha == ", alpha_num)))
    # Use deparse in label
    p <- p + geom_text(aes(x,y,label=paste0("alpha == ", deparse(alpha_num))), parse = TRUE, size = 30)
    p  
    

    And the output is:

    0 讨论(0)
提交回复
热议问题