Skip to content

ggplot to ggplotly doesn't work with customized 'fill' values in R #421

@speedreader

Description

@speedreader

Trying to use plotly and ggplot to make a geom_bar with a custom colored bar.

set.seed(8)
y <- rpois(1000, 2.9)
table(y)

holdThis <- as.data.frame(table(y))
holdThis$cumTotal <- cumsum(holdThis$Freq)
holdThis$percentage <- (as.numeric(holdThis$Freq)/10000) * 100
holdThis$y <- as.numeric(as.character(holdThis$y))

# In practice this will be generated dynamically, but for here I'll just fill them manually.
fillCol <- c('blue', 'blue','blue','blue','blue','blue','red','blue','blue','blue')

p <- ggplot(holdThis, aes(x=y, y=Freq)) + geom_bar(stat='identity', fill= fillCol, color="black", size = .25, alpha = .7) + scale_x_discrete(breaks = y)

ggplotly(p)

ggplot produces this (works):

screen shot 2016-01-23 at 3 14 04 pm

ggplotly(p) produces this message:
Warning message:
In if (!grepl(pat, x)) return(x) :
the condition has length > 1 and only the first element will be used

And this:
screen shot 2016-01-23 at 3 14 26 pm

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions