Closed bklingen closed 3 years ago
Hello,
Yes there's a bug somewhere with your first example, I'll investigate.
In your last example, bars are gray because colors names don't work, you have to use hex code.
To achieve what you desire, I see 2 options:
fillColor
:library(apexcharter)
plotdata <- data.frame(x=c("a","b"), counts=5:6, color=1:2, fillColor = c("#FE2E2E", "#FF8000"))
apex(
data = plotdata,
type = "column",
mapping = aes(x = x, y = counts, fillColor = fillColor)
)
fill
aes like you did but with stacked bars:library(tidyr)
plotdata1 <- complete(plotdata, x, color)
apex(
data = plotdata1,
type = "column",
mapping = aes(x = x, y = counts, fill = color)
) %>%
ax_chart(stacked = TRUE) %>%
ax_colors(c("#FE2E2E", "#FF8000"))
Hope it helps !
Victor
Wonderful, works perfectly, thanks!
Getting a bar chart with different colored bars is harder than you think, and the end result is still not satisfying as it shows empty (NA) labels: A natural (by
ggplot2
standards) approach is to try:but this "drops" the b category and produces![image](https://user-images.githubusercontent.com/4784206/107297973-72b85180-6a42-11eb-84f6-bed9591fdd6e.png)
One can complete the plotdata through
and then get two different colors for the two bars
but there are empty bars at each category on the x-axis (because of the NA's generated in![image](https://user-images.githubusercontent.com/4784206/107298900-4998c080-6a44-11eb-80ef-32424112af3a.png)
complete
):Ideally, I was hoping code like
would give two bars, the one over "a" in one red, the other over "b" in orange. Instead, I get:![image](https://user-images.githubusercontent.com/4784206/107299218-d93e6f00-6a44-11eb-8daf-f69df079fdb9.png)
But perhaps I don't quite understand how to get this with apexcharter. Thanks! Bernhard