UM-R-for-EnvSci-Registered-Student / General-Discussion

Public repo for general discussion about the course and assignments
1 stars 0 forks source link

custom theme not working as a function #7

Open gendronh opened 4 years ago

gendronh commented 4 years ago

When I made my theme as an object everything seemed to work fine, but once I made it into a function, for whatever reason, my plot comes out solid white. Exact same code, just added the chunk of code to make it a function. Anyone else have issues like this? Screen Shot 2020-11-01 at 5 16 30 PM Screen Shot 2020-11-01 at 5 18 06 PM

peperg commented 4 years ago

@gendronh,

Are you basing your theme on a previous one (e..g. theme_bw())? It is obvioulsy making the pannel.background() white. That could be because of the defaults on either the panel.background() itself or its parent object rect(). theme_bw() has a white panel background by default, so if you dont ove-ride that it will show it.

Let me know if that works.

Pepe

gendronh commented 4 years ago

my theme is based on theme_bw. I changed the panel background using panel.background = element_rect(fill='#306754'). My code worked as an object. I'm just not sure how changing my theme from an object to a function causes it to lose the panel background colour.

peperg commented 4 years ago

@gendronh , I think i might need to take a look at the code to see what is happening. Would you mind pushing the project as you have it to GitHub, i'll take a look!

gendronh commented 4 years ago

@peperg I just pushed the project to GitHub. Thanks for taking a look at it!

dlangenfeld commented 4 years ago

I am also having issues with this. My theme works as an object but doesn't work as a function

peperg commented 4 years ago

@gendronh,

Sorry it took me a bit, i just took a look. Interesting case!

so, here is the thing... both panel.border() and panel.background() are "daughters" of rect(), so both technically have fill and color arguments... they are sort of the same thing... same goes for plot.border() and plot.background(). So if you set the fill in the panel border, you are really just changing the panel background. If you change the color in the panel background, you are changing the border... a bit of a mess...

I had never encountered an issue with that, but i guess the defaults on rect() on theme_bw() are cascading down to the panel border and showing it with a white background.

i have solved it by changing this line in your code:

I have never encountered this issue before, so i'll do more digging, but at least we know how to fix it now. As to why it behaves different when used as an object or a function, i am not sure. It mush have to do with the specific use of the %+replace%, but i will try to figure it out.

If you do figure it out, please let me know!

peperg commented 4 years ago

@dlangenfeld,

Not sure if that explanation above applies to you, take a look and let me know.

dlangenfeld commented 4 years ago

@peperg for me nothing happens when I use my theme function after I saved it in the R script, but the exact same code when it was in my Rmarkdown script worked

peperg commented 4 years ago

@dlangenfeld, could you push your repo? I'll take a look