In R, how do I set the default color palette for all plotly plots?
I know in plot_ly() you can set colors=palette, but that works only for scatter plots and not for line plots. For line plots you have to set the colors for each trace individually.
Apparently in the current plotly-version (4.8.0) this feature exists. You can set a color palette by using the colors-argument inside the plot_ly()-wrapper. However this only works if you use the color-argument in each add_trace.
my_palette=c('#0099FF','#00FF99') # create my palette
plot_ly(colors=my_palette) %>% ## set the palette
add_trace(x=1:4,y=rbinom(4,10,0.4),type='scatter',mode='lines',hoverinfo='skip',color=as.factor('my first trace')) %>%
add_trace(x=1:4,y=rbinom(4,10,0.5),type='scatter',mode='lines',hoverinfo='skip',color=as.factor('the second'))
Since the color-functionality is fairly new in plotly I am optimistic that this functionality will continue to exist in future package versions (>4.8.0.).
I only found your question over my own question and it turns out that both our problems have a similar solution
Related
I am currently using Plots package in Julia with pyplot as the backend. I can choose color_palette and make plots by
pyplot(color_palette=:delta)
Plots.plot(x, y)
What is the syntax to define and use a custom color palette according to, for example, Okade and Ito below, for color-blind-friendliness? Thanks!
Just pass a Vector of RGB - see the docs here https://docs.juliaplots.org/latest/colors/#Misc-1 But that particular palette is actually built into Plots - so you can get it by specifying theme(:wong2) before plotting, it will change the palette and color gradient for the duration of the session.
I would like to change the default color scheme in ggplot2. That is, I would like to define a color scheme (say: viridis) at the one point in the script so that all subsequent ggplot diagrams will use this color scheme without having to call + scale_color_viridis() each time.
I've seen this SO post featuring update_geom_defaults(geom, new), but I could not find a way to explain this function to use a scheme such as viridis.
I have also tried to update the ggplot color, similar to this post, but, as #baptise pointed out, this approach does not really work.
In short:
define new color scheme, eg., viridis
call ggplot subsequently without adding + scale_color_viridis() but still this ggplot diagram uses the viridis color scheme.
It looks like
options(ggplot2.continuous.colour="viridis")
will do what you want (i.e. ggplot will look for a colour scale called
scale_colour_whatever
where whatever is the argument passed to ggplot2.continuous.colour—viridis in the above example).
library(ggplot2)
opts <- options(ggplot2.continuous.colour="viridis")
dd <- data.frame(x=1:20,y=1:20,z=1:20)
ggplot(dd,aes(x,y,colour=z))+geom_point(size=5)
options(oldopts) ## reset previous option settings
For discrete scales, the answer to this question (redefine the scale_colour_discrete function with your chosen defaults) seems to work well:
scale_colour_discrete <- function(...) {
scale_colour_brewer(..., palette="Set1")
}
I am currently using the Plots package and have it along with the PyPlot packages installed. With the code
using Plots
y = rand(10, 10)
pyplot()
plt = plot(y, st=:heatmap, clim=(0,1), color=:coolwarm, colorbar_title="y")
I am able to produce this
heat map
My question is how I can change the color gradient from its current setting (coolwarm which corresponds with a transition from red to gray to blue) to a new setting which has a gradient from red to green to blue. Is there some way to create a custom colorgradient and use that as an argument where I have 'coolwarm' in my sample code?
Yes. First of all there are numerous color libraries in Plots. Try clibraries(), then e.g. cgradients(:colorbrewer) or showlibrary(colorbrewer). In addition, you can make your own gradient with e.g. cgrad([:red, :green, :blue]) and pass that as the color argument.
I looked for the easthetics to make the histogram look better in my R code, nonetheless I was wondering if I could change the size of the bins or maybe the margin or put a color background in the plot WITHOUT using ggplot.
Thank you.
Using version.string R version 2.11.0 (2010-04-22)
quantmod "0.3-17"
Windows XP
When using the chartSeries function in quantmod with type="line" the line color that is displayed on the chart is green. I would like to change the color from green to another color.
It looks like i can change the chartTheme, but the theme does not explicitly have a variable to change the color of the plot display for lines.
I can change the line display color when using the plot() function - So is it possible to change the display of line plots to a different color using chartSeries() in quantmod?
Rather than cluttering its argument list with options controlling all aspects of chart appearance, chartSeries() has a single theme argument. theme accepts a chart.theme object that controls the colors of most parts of the plot, bundling all of those color choices into a single object.
The function chartTheme() creates chart.theme objects of the appropriate form. Among the options listed in ?chartTheme, up.col seems to control the color you are asking about:
require(quantmod)
getSymbols("YHOO")
chartSeries(YHOO, type="line",
theme = chartTheme("black", up.col='gold'))