Transparent R plot background in VS Code Jupyter Notebook - How to set default white background?
original issue on Github
Issue Description:
When generating R plots in VS Code's Jupyter Notebook (.ipynb files), the plot backgrounds appear transparent by default, making visualizations hard to read. This issue:
- ❌ Occurs in Jupyter Notebooks with R kernel
- ✅ Does NOT occur in standard R scripts (.R files)
- ✅ Python plots with matplotlib work normally in the same notebook
Minimal Reproducible Example:
x <- c(1, 2, 3, 4, 5)
y <- c(2, 4, 6, 8, 10)
plot(x, y, type = "o", col = "blue", pch = 16, main = "Simple Plot")
legend("topleft", legend = "y = 2x", col = "blue", pch = 16, lty = 1)

Expected vs Actual Behavior:
|
Result |
Expected |
White background (as in .R files) |
Actual |
Transparent background |
Temporary Workaround:
par(bg = "white") # Required before each plot
plot(...)
- This manual solution is not ideal for notebooks with multiple plots

Environment:
- R kernel: 4.4.2
- jupyter_client: 8.6.0
- jupyter_core: 5.7.2
- jupyterlab: 4.2.5
- OS: Windows 11
- Tested on both dark/light themes in VS Code
Additional Context:
- Issue persists across notebook restarts
- No relevant jupyterlab/IRkernel settings found
- Graphics device: png() (default in Jupyter)
Question:
- How to permanently configure R plots in Jupyter Notebooks to use a white background by default, without manually adding
par(bg = "white")
before each plot?