Here's what I have, so far:
f1 <- list(
family = "Arial, sans-serif",
size = 25,
color = "white"
)
f2 <- list(
family = "Old Standard TT, serif",
size = 14,
color = "black"
)
a <- list(
title = "SALES PER SONG",
titlefont = f1,
showgrid = FALSE,
showticklabels = TRUE,
showline=TRUE,
tickangle = 45,
tickfont = f2
)
salesplot <-plot_ly(producersales, type="scatter", x=Producer, y=SalesPerSong, color=SongRange, colors=cols, mode="markers", size=SalesPerSong) %>%
layout(xaxis = a, yaxis = a)
I tried adding paper_bgcolor=#00000000, plot_bgcolor=#00000000
after the x and y axis information within layout()
, but when I run the command, I get the plus sign. I don't know what to do, so any help is appreciated. Thanks!
To actually visualize a transparent background the image has to be stored as a PNG image, this can be done ggsave () function. In this approach, after the plot has been created normally, theme () function is added to it with rect parameter. To rect, element_rect () function is passed with parameter fill set to transparent.
Example 1 shows how to export a ggplot2 plot with transparent rectangle elements. Next, we can use the ggsave function to write our transparent plot to a PNG file: Have a look at your current working directory after running the previous R code. You should find a ggplot2 plot with transparent background.
Note that transparent backgrounds will also apply to exported images. Which can render black label text invisible in some image viewing applications, including Windows 10's default Photos tool.
Plotly's graph description places attributes into two categories: traces(which describe a single series of data in a graph) and layoutattributes that apply to the rest of the chart, like the title, xaxis, or annotations).
Just try:
salesplot <-plot_ly(producersales, type="scatter", x=Producer, y=SalesPerSong, color=SongRange, colors=cols, mode="markers", size=SalesPerSong) %>%
layout(xaxis = a, yaxis = a) %>%
layout(plot_bgcolor='rgb(254, 247, 234)') %>%
layout(paper_bgcolor='rgb(254, 247, 234)') #will also accept paper_bgcolor='black' or paper_bgcolor='transparent'
You can change the rgb numbers to fit your needs.
I find toy need to use rgba AND fig_bgcolor in layout
plt %>%
layout(plot_bgcolor = "rgba(0, 0, 0, 0)",
paper_bgcolor = "rgba(0, 0, 0, 0)",
fig_bgcolor = "rgba(0, 0, 0, 0)")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With