-4

This is a barplot I have:

How can I have a black outline for each bar and also, change the font size of the axis label and values on the label?

mm1=melt(data[,c('label','cut_scorer1','cut_scorer2')], id = 1)
assign(cut_score,ggplot(mm1, aes(x = label, y = value, width = 0.8)) + 
    geom_bar(aes(fill = variable), stat = "identity", position = "dodge")+ sale_fill_manual(values=alpha(c('light green','dark green'),0.7), name = "Scorer", 
    labels = c("1", "2")) + 
    labs(title = paste(subject_name,"Cutting", sep = " - "), x = "", y = 
    "Score") + 
    theme(text = element_text(size = 15)) + coord_cartesian( ylim = 
    c(min(mm1$value),max(mm1$value))))
Jaap
  • 81,064
  • 34
  • 182
  • 193
Czar.Wolfgang
  • 67
  • 2
  • 3
  • 12
  • 1
    When asking for help, you should include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick May 01 '18 at 19:57
  • 1
    Possible duplicate of [ggplot2: geom\_bar stacked barplot, specify bar outline color](https://stackoverflow.com/questions/26267417/ggplot2-geom-bar-stacked-barplot-specify-bar-outline-color) – code11 May 01 '18 at 19:58
  • This is not really a duplicate of the above question, as that one is specifically for stacked barplots, which requires an alternative approach using `cut()`. – Marcus Campbell May 01 '18 at 20:41
  • cut() does not work for group plots – Czar.Wolfgang May 01 '18 at 21:27

2 Answers2

1

I really recommend taking a look at the documentation for geom_bar() (as well as the basic ggplot2 documentation), but this might help get you started.

You can add an outline to your bars by using colour = "black", and you can change the axis labels by using labs(). We use the arguments within theme() to change the font size on your axis labels and tickmarks. See the code below:

# example dataframe
df <- data.frame(time = factor(c("Lunch","Dinner"), levels=c("Lunch","Dinner")),
                 total_bill = c(14.89, 17.23))

plot <- ggplot(data = df, aes(x = time, y = total_bill, fill = time)) +
        geom_bar(colour = "black", stat = "identity") +
        labs(x = "Meal", y = "Total Bill") +
        theme(axis.title.x = element_text(size = 13, face = "bold"),
              axis.title.y = element_text(size = 13, face = "bold"),
              axis.text.x = element_text(size = 12),
              axis.text.y = element_text(size = 12))
print(plot)

enter image description here

Marcus Campbell
  • 2,746
  • 4
  • 22
  • 36
0

I found the solution, thanks.

I added colour = "black" inside geom_bar but outside aes

mm1 = melt(data[,c('label','cut_scorer1','cut_scorer2')], id = 1) assign(cut_score,ggplot(mm1, aes(x = label, y = value, width = 0.8)) + geom_bar(aes(fill = variable), stat = "identity", colour = "black", position = "dodge") + scale_color_manual(values = 'black') + scale_fill_manual(values=alpha(c('light green','dark green'),0.7), name = "Scorer", labels = c("1", "2")) + labs(title = paste(subject_name,"Cutting", sep = " - "), x = "", y = "Score") + theme(text = element_text(size = 15)) + coord_cartesian( ylim = c(min(mm1$value),max(mm1$value))))

Czar.Wolfgang
  • 67
  • 2
  • 3
  • 12