How to change colour for barplot in ggplot2 using viridis package?

Ar1229

enter image description hereI am trying to make a ggplot with the viridis package (magma option) for colouring the bars. I keep going to the default colour option.

here is my code:

library(ggplot2)
library(viridis)
barplotforraredisease <- data. frame(family = c(" Singleton", "Family of 2", "Family of 3", "Family of 4", "Family of 5"), total members=c(108,52,121,9,2))

p <- ggplot (data=barplotforraredisease, aes (x=family, y=total members))+geom bar(stat = "identity") +geomtext(aes (label=total members), vjust= -0.3, size = 3.5) +theme_minimal() +ggtitle( "Number of families tested")+scale color viridis(discrete = TRUE, option = "viridis")

I've attached a screenshot of what my plot looks like, I would appreciate any help.

SamR

The code you posted has some underscores replaced with spaces.

Once that is fixed, this should work. Note that you need to set the fill value to the column that you want, change scale_color_viridis() to scale_fill_viridis() and set option = "magma".

ggplot(
    data=barplotforraredisease, aes(
        x=family, y=total_members, fill=family)
    ) + 
    geom_bar(stat = "identity") + 
    geom_text(aes(label=total_members), vjust= -0.3, size = 3.5) +
    theme_minimal() + 
    ggtitle( "Number of families tested") + 
    scale_fill_viridis(discrete = TRUE, option = "magma")

enter image description here

Data:

barplotforraredisease  <- structure(list(family = c(" Singleton", "Family of 2", "Family of 3",
"Family of 4", "Family of 5"), total_members = c(108, 52, 121,
9, 2)), class = "data.frame", row.names = c(NA, -5L))

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to design the colour of barplot using ggplot

How to change legend title and key order and colour to a multi-stacked barplot in R with ggplot2

How to change colour and position of geom_text for just one bar in a barplot in ggplot2 (R)?

ggplot2 - Change `geom_rect` colour in a stacked barplot

How to plot a barplot using ggplot2

Gradient colour fill a barplot in ggplot2

Mapping dates to the viridis colour scale in ggplot2

Manually change colour of one factor level in ggplot2 stacked barplot

How to colour grouped barplot by group, not by conditon in ggplot?

How to change ggplot2 x-axis values in barplot?

How to change background colour of legend in ggplot2?

How to change the text in the colour legend of ggplot2

ggplot2 barplot bar colour can't be changed properly

How do I change the color of my bar plot using ggplot2 package of R?

Change aestesics in ggplot2 barplot

Using ggplot2 and viridis, fill histogram based on other variable

Bubble map legend color in ggplot2 using viridis

How to change barplot in ggplot for R

How to change the colour of the lines in ggplot

ggplot2 barplot labels using counts

Multiple barplot using ggplot2

Barplot using ggplot2 for 4 variables

How to manually change the fill color of barplot when stat='count' in ggplot2

How to change the colour for missing value in geom_point of ggplot2?

ggplot2: how to change the width of colour aesthetic in a bar/col geometry?

ggplot2: geom_bar fill colour; how to change to different grouping of data

How to change colour of selected node or edge when using the visNetwork package in R?

Change the colour of a subset of labels in barplot R

how do I specify colour when using fill in ggplot2 and how to print pvalue onto plot