Change the tick level in a legend

Hi all, I am using the titanic open source dataset to experiment with scatter plots in plotly. My graph is looking good with the exception of one issue. I noticed that the legend on the right contains values from 0 to 1 in increments of 0.2. I’d like to remove the 0.2 ticks and show only values between 0 and 1 (or label as True or False)

Is there a way do do this via a legend method setting?

Thanks
Jonathan

titanic.sp.df <- read.csv(file=“train.csv”, header=TRUE, sep=",")

What is the mean and median age

mean(titanic.sp.df$Age, na.rm=TRUE) #29.699
median(titanic.sp.df$Age, na.rm=TRUE) #28

replace all Age NA values with the median value

titanic.sp.df$Age[is.na(titanic.sp.df$Age)] <- 28

col_scheme <- c("#3a6587", “#aeb3b7”)

p.scatter2 <- plot_ly(data = titanic.sp.df, x = ~Fare, y = ~Age,
type = ‘scatter’, mode = ‘markers’,
color = ~Survived, colors = col_scheme) %>%
layout(title = “Titanic Passenger Age & Fare by Survial Type”,
xaxis = list(title = “Fare (In Pounds)”, showgrid = FALSE),
yaxis = list(title = “Age (In Years)”, showgrid = FALSE),
legend = l)

p.scatter2

@jonathan.dunne, The automatic color grouping that plotly for R has will assume that numerical data is sequential by default and so it will create a colorbar legend for your data. If you replace color = ~Survived with color = ~factor(Survived) your plot will show a legend for values of 0 and 1 instead of the colorbar. You could then change the values from 0 to ‘False’ and from 1 to ‘True’ in the dataframe to change the labels on your plot.

1 Like

Many thanks Michael, changing to a factor did the trick.