r - change color of only one bar in ggplot -


i want color 1 bar in ggplot. data frame:

area <- c("północ", "południe", "wschód", "zachód") sale <- c(16.5, 13.5, 14, 13) df.sale <- data.frame(area, sale) colnames(df.sale) <- c("obszar sprzedaży", "liczba sprzedanych produktów (w tys.)") 

and code plotting:

plot.sale.bad <- ggplot(data=df.sale, aes(x=area, y=sale, fill=area)) +   geom_bar(stat="identity") +   scale_fill_manual(values=c("black", "red", "black", "black")) +   xlab(colnames(df.sale)[1]) +   ylab(colnames(df.sale)[2]) +   ggtitle("porównanie sprzedaży")  

i have 1 bar colored , 3 others have default color (darkgrey, not black, looks bad me). how can change color of on bar or how name of default color of bars put them instead of black?

option 1: change color of 1 bar. following henrick's suggestion, can create new variable nas default color , character strings/factors non-default colors (the first 1 happens red):

area.color <- c(na, "withcolor", na, na) plot.sale.bad <- ggplot(data=df.sale, aes(x=area, y=sale, fill=area.color)) +   geom_bar(stat="identity") +   xlab(colnames(df.sale)[1]) +   ylab(colnames(df.sale)[2]) +   ggtitle("porównanie sprzedaży")  plot.sale.bad 

option 2: find name of default dark gray color like. not default color if remove scale_fill_manual line in original code (in case, 4 different pastels), assume mean grey color produced code chunk above paragraph, bars area.color==na. in case, might @ source code (or args, anyway) scale_fill_discrete:

> args(scale_fill_discrete) # function (..., h = c(0, 360) + 15, c = 100, l = 65, h.start = 0,  #     direction = 1, na.value = "grey50")  # null 

the default na.value "grey50". if wanted use scale_fill_manual, so:

plot.sale.bad <- ggplot(data=df.sale, aes(x=area, y=sale, fill=area)) +   geom_bar(stat="identity") +   scale_fill_manual(values=c("grey50", "red", "grey50", "grey50")) +   xlab(colnames(df.sale)[1]) +   ylab(colnames(df.sale)[2]) +   ggtitle("porównanie sprzedaży")  plot.sale.bad 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -