jrnold / ggthemes

Additional themes, scales, and geoms for ggplot2
http://jrnold.github.io/ggthemes/
1.33k stars 226 forks source link

Error in FUN(X[[i]], ...) : Theme element 'text' has NULL property: margin, debug #57

Closed LeidenuniJM closed 8 years ago

LeidenuniJM commented 8 years ago

Anyone familiar with this error and can help me out?

I get this error every time I try to plot my data:

jrnold commented 8 years ago

Can you provide a minimal example? From the error message it seems like your versions of ggplot2 and ggthemes are not up to date. Can you update them and try again?

LeidenuniJM commented 8 years ago

I'm not very experienced yet with Rstudio but basically I'm running a CPHDF5 file analysis and via the runApp timeplots I can launch a browser from the program CellProfiler h5 GUI where I can plot my data and download the graphs as a pdf.

So I tried the update and it now says all my packages in Rstudio are up to date.

But I still get these errors in the console:

Error in FUN(X[[i]], ...) : Theme element 'text' has NULL property: margin, debug Warning: axis.ticks.margin is deprecated. Please set margin property of axis.text instead

and this one:

perl is deprecated. Please use regexp instead

Not sure how to fix that one either. Hope you can help

jrnold commented 8 years ago

Without example code that produces the error, there's not much I can do.

aannasw commented 8 years ago

Hello, I'm getting the same error as the OP.

I am trying to create a custom theme and followed the details in this post http://docs.ggplot2.org/dev/vignettes/themes.html. I tried updating both ggplot2 and ggthemes to the dev version, and got a 'cannot find ggplot2' error, so I uninstalled both and reinstalled the stable versions of both. I've also updated my R version to 3.2.3.

Thanks so much for your help.


theme_custom <- function(base_size = 12, base_family = "Helvetica") {
    theme(
    line =               element_line(color = "black", size = 0.5, linetype = 1, lineend = "butt"),
    rect =               element_rect(fill = "white", color = "black", size = 0.5,
                                      linetype = 1),
    text =               element_text(family = base_family, face = "plain",
                            color = "black", size = base_size,
                            hjust = 0.5, vjust = 0.5, angle = 0, lineheight = 0.9),
    axis.text =          element_text(size = rel(1.1), color = "snow4", 
                                      margin(0.1, 0.1, 0.1, 0.1, unit = "cm")),
    strip.text =         element_text(size = rel(1.3), face = "bold"),

    axis.line =          element_blank(),
    axis.text.x =        element_text(vjust = 1),
    axis.text.y =        element_text(hjust = 1),
    axis.ticks =         element_blank(),
    axis.title.x =       element_text(color="snow4"),
    axis.title.y =       element_text(angle = 90, color="snow4"),
    axis.ticks.length =  unit(0.15, "cm"),
    #axis.ticks.margin = unit(0.1, "cm"),
    #axis.ticks =         margin(0.1, 0.1, 0.1, 0.1, unit = "cm"),

    legend.background =  element_blank(),
    legend.margin =      unit(0.2, "cm"),
    legend.key =         element_blank(),
    legend.key.size =    unit(1.2, "lines"),
    legend.key.height =  NULL,
    legend.key.width =   NULL,
    legend.text =        element_text(size = rel(0.8), color = "snow4"),
    legend.title =       element_text(size = rel(0.9), face = "bold", hjust = 0, 
                                      color = "snow4"),
    legend.title.align = NULL,
    legend.position =    "bottom",
    legend.direction =   "vertical",
    legend.justification = "center",
    legend.box =         NULL,

    panel.background =   element_blank(),
    panel.border =       element_blank(),
    panel.grid.major =   element_line(color="gray95"),
    panel.grid.minor =   element_blank(),
    panel.margin =       unit(0.25, "lines"),

    strip.background =   element_rect(fill = "snow2"),
    strip.text.x =       element_text(),
    strip.text.y =       element_text(angle = -90),

    plot.background =    element_rect(fill="snow2"),
    plot.title =         element_text(size = rel(1.3), color="snow4", face = "bold", 
                                      hjust = 1),
    plot.margin =        unit(c(1, 1, 0.5, 0.5), "lines"),

    complete = TRUE
  )
}
# Check that it is a complete theme
attr(theme_custom(), "complete")
--------------------------------------------------
[1] TRUE
--------------------------------------------------
# Load 'faithful' dataset from datasets package and create sample plot
data(faithful)
ggplot(aes(x = eruptions, stat = "bin"), data = faithful) + geom_histogram(binwidth = .05) + theme_custom()
--------------------------------------------------
Error in FUN(X[[i]], ...) : 
  Theme element 'text' has NULL property: margin, debug
--------------------------------------------------

If I create the custom theme with the axis.ticks.margin uncommented, the complete theme check evaluates to:

> attr(theme_custom(), "complete")
[1] TRUE
Warning message:
`axis.ticks.margin` is deprecated. Please set `margin` property  of `axis.text` instead 
jrnold commented 8 years ago

I'll answer this, but first I'll let you know that this is not the appropriate venue for this question. These issues are for bugs/issues with the ggthemes package, and while it appears you are using a theme in ggplot2, it doesn't appear that you are using anything from ggthemes. You would want to look at stackoverflow or the ggplot2 mailing list, or if there is a problem with the ggplot2 documentation, file an issue at https://github.com/hadley/ggplot2/issues.

It does look like the documentation for ggplot2 may not have been updated to account for changes made with ggplot2 2.0.0. ggplot2 version 2.0.0 added the elements margin and debug to element_text, so you need to change the text element of the theme to

    text =               element_text(family = base_family, face = "plain",
                                      color = "black", size = base_size,
                                      hjust = 0.5, vjust = 0.5, angle = 0, lineheight = 0.9,
                                      margin = margin(), debug = FALSE),
aannasw commented 8 years ago

Ah, I wasn't sure where the problem was. Thanks so much for taking the time! Works now.

wmayner commented 8 years ago

For anyone who's still having this issue, it's been raised in the ggplot2 repo at hadley/ggplot2#1489.

subasish commented 8 years ago

This is the continution from this thread. Here's the sessionInfo:

R version 3.2.3 (2015-12-10)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11 (El Capitan)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
 [1] parallel  compiler  grid      stats     graphics 
 [6] grDevices utils     datasets  methods   base     

other attached packages:
 [1] ggthemes_3.0.1  RPMG_2.2-1      vcd_1.3-2      
 [4] boot_1.3-17     lme4_1.1-7      Rcpp_0.12.2    
 [7] reshape2_1.4.1  GGally_1.0.1    gridExtra_0.9.1
[10] ggplot2_2.0.0   reshape_0.8.5   arules_1.1-6   
[13] Matrix_1.2-3   

Here's the error message:

Error in FUN(X[[i]], ...) : 
  Theme element 'text' has NULL property: margin, debug
In addition: Warning message:
`axis.ticks.margin` is deprecated. Please set `margin` property  of `axis.text` instead
matheuscburger commented 8 years ago

I'm getting the same error. Here is a minimal example:

library("ggplot2")
library("ggthemes")
aux <- data.frame(bar=c("b1", "b2", "b3"), value=c(10, 5, 1))
ggplot(aux, aes(x=bar, y=value)) +
     geom_bar(stat="identity", aes(fill=bar)) +
     theme_gdocs()

I got the following error

Error in FUN(X[[i]], ...) : 
  Theme element 'text' has NULL property: margin, debug
In addition: Warning message:
`axis.ticks.margin` is deprecated. Please set `margin` property  of `axis.text` instead

And this is my R info:

R version 3.3.1 (2016-06-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 8 (jessie)

locale:
 [1] LC_CTYPE=en_US.utf8       LC_NUMERIC=C              LC_TIME=en_US.utf8        LC_COLLATE=en_US.utf8     LC_MONETARY=en_US.utf8   
 [6] LC_MESSAGES=en_US.utf8    LC_PAPER=en_US.utf8       LC_NAME=C                 LC_ADDRESS=C              LC_TELEPHONE=C           
[11] LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C      

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
[1] ggthemes_2.2.1       ggplot2_2.1.0        BiocInstaller_1.18.5 vimcom_1.2-6         setwidth_1.0-4       colorout_1.1-1      

loaded via a namespace (and not attached):
 [1] labeling_0.3     colorspace_1.2-6 scales_0.4.0     plyr_1.8.4       tools_3.3.1      gtable_0.2.0     Rcpp_0.12.5      grid_3.3.1      
 [9] proto_0.3-10     munsell_0.4.3
Matherion commented 6 years ago

Just a quick thank-you to jrnold: your solution from Jan 17, 2016 also helped me, so thanks!