R-CoderDotCom / calendR

Ready to print calendars with ggplot2
https://r-coder.com/calendar-plot-r/
MIT License
252 stars 35 forks source link

Legend Background #28

Open msgoussi opened 1 year ago

msgoussi commented 1 year ago

imp.dates <- rep(NA, 366) imp.dates[c(1, 50, 12, 125, 80, 99, 102, 205, 266, 360)] <- "special"

calendR(year = 2020, # Year mbg.col = 2, # Background color for the month names months.col = "white", # Text color of the month names special.days = imp.dates, special.col = "pink", # Color of the special.days months.pos = 0.5, bg.col = "#dbd4cc", legend.pos = "left" )

I am wondering how to color the bg color of legend!

mschilli87 commented 1 year ago

Could you add a screenshot of what you get and a modified one showing what you'd like to get instead?

msgoussi commented 1 year ago

if I run the above code, the background of the legend is white. so I am wondering how to change the legend's bg. Rplot

mschilli87 commented 1 year ago
library(calendR)
library(ggplot2)

imp.dates <- rep(NA, 366)
imp.dates[c(1, 50, 12, 125, 80, 99, 102, 205, 266, 360)] <- "special"

calendR(year = 2020, # Year
mbg.col = 2, # Background color for the month names
months.col = "white", # Text color of the month names
special.days = imp.dates,
special.col = "pink", # Color of the special.days
months.pos = 0.5,
bg.col = "#dbd4cc",
legend.pos = "left"
) + theme(legend.background = element_blank())

or

imp.dates <- rep(NA, 366)
imp.dates[c(1, 50, 12, 125, 80, 99, 102, 205, 266, 360)] <- "special"

calendR::calendR(year = 2020, # Year
mbg.col = 2, # Background color for the month names
months.col = "white", # Text color of the month names
special.days = imp.dates,
special.col = "pink", # Color of the special.days
months.pos = 0.5,
bg.col = "#dbd4cc",
legend.pos = "left"
) + ggplot2::theme(legend.background = ggplot2::element_blank())

edit: The above examples remove the background entirely. If you want to change the color, replace element_blank by element_rect:

library(calendR)
library(ggplot2)

imp.dates <- rep(NA, 366)
imp.dates[c(1, 50, 12, 125, 80, 99, 102, 205, 266, 360)] <- "special"

calendR(year = 2020, # Year
mbg.col = 2, # Background color for the month names
months.col = "white", # Text color of the month names
special.days = imp.dates,
special.col = "pink", # Color of the special.days
months.pos = 0.5,
bg.col = "#dbd4cc",
legend.pos = "left"
) + theme(legend.background = element_rect(fill = "lavender"))

or

imp.dates <- rep(NA, 366)
imp.dates[c(1, 50, 12, 125, 80, 99, 102, 205, 266, 360)] <- "special"

calendR::calendR(year = 2020, # Year
mbg.col = 2, # Background color for the month names
months.col = "white", # Text color of the month names
special.days = imp.dates,
special.col = "pink", # Color of the special.days
months.pos = 0.5,
bg.col = "#dbd4cc",
legend.pos = "left"
) + ggplot2::theme(legend.background = ggplot2::element_rect(fill = "lavender"))