[![enter image description here][2]][2]
I want to have a flipped barchart with a color gradient to distinguish the bars. Below are the first 20 rows of my dataset bb_count is my dataset and the code to generate the barplot. The barplot is plotted correctly but the color gradient is not being applied, instead I get the error:
ERROR while rich displaying an object: Error: Discrete value supplied to continuous scale
bb_count <- bb %>%
count(chord, sort = TRUE)
# chord n
# C:maj 1183
# G:maj 1140
# A:maj 1071
# D:maj 1054
# F:maj 859
# E:maj 839
# Bb:maj 718
# B:maj 503
# Ab:maj 375
# Eb:maj 360
# A:min 328
# E:min 298
# Db:maj 293
# D:min 250
# B:min 236
# N 201
# E:min7 186
# C:min 176
# D:7 176
# A:min7 170
# Creating a bar plot from `bb_count`
bb_count %>%
slice(1:20) %>%
mutate(share = n/sum(n)) %>%
mutate(chord = reorder(chord, share)) %>%
ggplot(aes(x = chord, y = share, fill = chord)) +
geom_bar(stat = 'identity', width = 0.95) +
coord_flip() +
scale_fill_gradient(low = "green", high = "red") +
xlab("Share of total chords") +
ylab("Chord")
dput(bb_count)
is shorter and easier to reproduce than showing the console output. Better still, dput us the output of your pipeline just before theggplot()
line, i.e. store the result from everything up to themutate(chord..
line. Then you'd see that the output fromreorder(chord, ...)
is categorical not numerical. – smcichord
. (Usedput
not console. We need to see if it's categorical). – smci