I want a barplot that outlines per unit in the y-axis. For example, the plot below using the iris dataset will plot a smooth barplot, however what I want is to outline each unit. I drew in the box to illustrate.
library(ggplot2)
freqtable <- table(iris$Petal.Width)
df <- as.data.frame.table(freqtable)
colnames ( df ) = c( "Width", "Freq")
df$Width = as.numeric ( as.character ( df$Width ) )
ggplot(df[ df$Width > 2.2, ] , aes( Width , Freq)) +
geom_bar(position="stack", stat="identity", fill="tomato2")

A bit of a hack but this does the job :
library(tidyverse)
df2 <-
uncount(df[ df$Width > 2.2, ] , Freq) %>%
mutate(Freq=1)
ggplot(df2, aes( Width , Freq)) +
geom_bar(position="stack", stat="identity", fill="tomato2", color = "black")

Created on 2021-09-12 by the reprex package (v2.0.1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With