When I create a plot in the RStudio viewer pane with plotly, I am left with a large white margin around the plot. This is normally fine, but not when using a non-standard color scheme. Moreover, this white margin seems to also exist when the image is exported, or generated in RMarkdown etc.
Does anyone know of a way to remove this?
Here is some example code to demonstrate:
library(plotly)
month <- c('January', 'February', 'March', 'April', 'May', 'June', 'July',
'August', 'September', 'October', 'November', 'December')
high_2014 <- c(28.8, 28.5, 37.0, 56.8, 69.7, 79.7, 78.5, 77.8, 74.1, 62.6, 45.3, 39.9)
low_2014 <- c(12.7, 14.3, 18.6, 35.5, 49.9, 58.0, 60.0, 58.6, 51.7, 45.2, 32.2, 29.1)
data <- data.frame(month, high_2014, low_2014)
data$average_2014 <- rowMeans(data[,c("high_2014", "low_2014")])
#The default order will be alphabetized unless specified as below:
data$month <- factor(data$month, levels = data[["month"]])
plot_ly(
data
,x = ~month
,y = ~high_2014
,type = 'scatter'
,mode = 'lines'
,line = list(color = 'rgba(0,100,80,1)')
,showlegend = FALSE
,name = 'High 2014'
)%>%
add_trace(
y = ~low_2014
,type = 'scatter'
,mode = 'lines'
,fill = 'tonexty'
,fillcolor='rgba(0,100,80,0.2)'
,line = list(color = 'rgba(0,100,80,1)')
,showlegend = FALSE
,name = 'Low 2014'
)%>%
layout(
title = "High and Low Temperatures in New York"
,paper_bgcolor='navy'
,plot_bgcolor='rgb(229,229,229)'
,bgcolor = "black"
)
Thanks, Tom