Conditional formatting of data points in scatterplot with connected points - r

Based on the following data frame and plot, I would like to conditionally change the colour of data points to black when did.it=="y". The shape of the dots and the colour of the lines, however, should remain unchanged. How can I do that?
set.seed(4887)
Strain <- rep(c(rep("A", times = 2), rep("B", times = 4)), times = 2)
Sex_ID <- rep(c("M_1", "F_2", "M_3", "F_4", "M_5", "F_6"), times = 2)
State <- rep(c("virgin", "mated", "expecting", "parent"), each = 6)
Huddling <- runif(8, 1.5, 3.8)
did.it<-rep(c("y","n","n"), times=8)
d <- data.frame(Strain, Sex_ID, State, Huddling, did.it)
library(tidyr)
d <- d %>%
separate(Sex_ID, c('Sex', 'ID'), sep = '_')
ggplot(d, aes(x = factor(State), y = Huddling, color = Sex, group = ID, shape = ID))+
facet_grid(Strain ~ ., scales = 'free_y') +
geom_point(size = 3, position = position_dodge(width=0.3), show.legend = F) +
geom_line(size = 0.7, position = position_dodge(width=0.3)) +
scale_color_manual(values = c('red4', 'midnightblue')) +
scale_fill_manual(values = "white") +
scale_x_discrete(limits = c("virgin", "mated", "expecting", "parent"),
labels = c("Virgin", "Mated", "Expecting", "Parent")) +
labs(y = "Time huddling (s)", x = "Reproductive stage") +
theme_classic() +
theme(axis.line.x = element_line(color = "black", size = 1),
axis.line.y = element_line(color = "black", size = 1),
axis.text = element_text(size = 17),
axis.title = element_text(size = 19,face = "bold"),
legend.title = element_text(size = 17),
legend.text = element_text(size = 15),
plot.title = element_text(lineheight = .8, face = "bold",size = 22))

You get part way there by just doing:
geom_point(size = 3, aes(color = did.it) ...) +
...
scale_color_manual(values = c('red4', 'midnightblue', 'orange', 'black')) ...
But this doesn't leave the points' colours unchanged when did.it is FALSE. So:
d$point_col <- ifelse(d$did.it=='y', 'y', d$Sex)
ggplot(d, aes(x = factor(State), y = Huddling, color = Sex, group = ID, shape = ID))+
facet_grid(Strain ~ ., scales = 'free_y') +
geom_point(size = 3, aes(color = point_col), position = position_dodge(width=0.3),
show.legend = F) +
geom_line(size = 0.7, position = position_dodge(width=0.3)) +
scale_color_manual(values = c('red4', 'midnightblue', 'black')) +
scale_fill_manual(values = "white") +
scale_x_discrete(limits = c("virgin", "mated", "expecting", "parent"),
labels = c("Virgin", "Mated", "Expecting", "Parent")) +
labs(y = "Time huddling (s)", x = "Reproductive stage")
(Plus your extra theme statements.)

Related

Get cartesian coordinates for plot area ggplot2

I would like to position labels close to the legend.
In the code below I have hardcoded (x,y) values in geom_label to get desired result for the current dataframe:
# Creating dataframe
library(ggplot2)
values <- c(rep(0,2), rep(2,3), rep(3,3), rep(4,3), 5, rep(6,2), 8, 9, rep(11,2) )
obs_number <- c(rep(18,18))
value_1 <- c(rep(4,18))
value_2 <- c(rep(7,18))
value_3 <- c(rep(3,18))
data_to_plot <- data.frame(values, obs_number, value_1, value_2, value_3)
# Calculate max frequency value for using in `geom_label`
frequency_count <- data_to_plot %>% group_by(values) %>% count()%>% arrange(n)
max_frequency <- max(frequency_count$n)
# Plot
ggplot(data_to_plot, aes(x = values)) +
geom_histogram(aes(y = ..count..), binwidth = 1, colour= "black", fill = "white") +
geom_density(aes(y=..count..), fill="blue", alpha = .25)+
geom_vline(aes(xintercept = value_1),
color="red", linetype = "dashed", size = 0.5, alpha = 1) +
geom_vline(aes(xintercept = value_1),
color="forestgreen", linetype="dashed", size = 0.5, alpha = 1) +
geom_vline(aes(xintercept = value_3),
color="purple", linetype = "dashed", size = 0.5, alpha = 1) +
geom_label(aes(label = obs_number, y = max_frequency*0.87, x = (max(values) - 2.2), color = 'blue'), size = 3.5, alpha = 1) +
geom_label(aes(label = value_1, y = max_frequency * 0.83, x = (max(values) - 2.2 ), color = 'forestgreen'), size = 3.5, alpha = 1) +
geom_label(aes(label = value_2, y = max_frequency * 0.79, x = (max(values) - 2.2) , color = 'purple'), size = 3.5, alpha = 1) +
geom_label(aes(label = value_3, y = max_frequency * 0.75, x = (max(values) - 2.2) , color = 'red'), size = 3.5, alpha = 1) +
scale_color_manual(name="Values",
labels = c("Observations number",
"value_1",
"value_2",
"value_3"
),
values = c( "blue",
"forestgreen",
"purple",
"red")) +
labs(title = "relevant_title", y = "Distribution fors DLT values", x = "DLT for the route: average values per batch") +
theme(plot.title = element_text(hjust = 0.5),
axis.title.x = element_text(colour = "darkblue"),
axis.text.x = element_text(face="plain", color="black",
size=10, angle=0),
axis.title.y = element_text(colour = "darkblue"),
axis.text.y = element_text(face="plain", color="black",
size=10, angle=0),
legend.position = c(.90, .80)
)+
labs(title="DLT values", y = "frequency", x = "days")+
scale_x_continuous(breaks = seq(0, max(data_to_plot$values), 1))
This is desired result:
But this will not work for all datasets.
Question:
How can I get cartesian coordinates of the plot area, so I would replace max_frequency and max(values) in geom_label and align labels with the legend, given that legend.position = c(.90, .80).
Other alternatives are also welcome.
Under the flag of 'alternatives are also welcome': why not use a text glyph for the geom_vline()s and override the actual labels?
I rearranged the code a bit for my own understanding, but here is an example:
library(tidyverse)
#> Warning: package 'tibble' was built under R version 4.0.3
#> Warning: package 'tidyr' was built under R version 4.0.3
#> Warning: package 'readr' was built under R version 4.0.3
#> Warning: package 'dplyr' was built under R version 4.0.3
values <- c(rep(0,2), rep(2,3), rep(3,3), rep(4,3), 5, rep(6,2), 8, 9, rep(11,2) )
obs_number <- c(rep(18,18))
value_1 <- c(rep(4,18))
value_2 <- c(rep(7,18))
value_3 <- c(rep(3,18))
data_to_plot <- data.frame(values, obs_number, value_1, value_2, value_3)
# Extra dataframe for storing the xintercepts and labels
vals <- data.frame(xintercept = c(18, 4, 7, 3),
label = c("Observations number", "value_1", "value_2", "value_3"))
frequency_count <- data_to_plot %>% group_by(values) %>% count()%>% arrange(n)
max_frequency <- max(frequency_count$n)
ggplot(data_to_plot, aes(x = values)) +
geom_histogram(aes(y = ..count..),
binwidth = 1, colour= "black", fill = "white") +
geom_density(aes(y=..count..),
fill="blue", alpha = .25)+
geom_vline(aes(xintercept = xintercept, color = label),
data = vals[2:nrow(vals), ],
linetype = "dashed", size = 0.5, alpha = 1,
# Give different legend glyph for vlines
key_glyph = draw_key_text) +
scale_color_manual(
name= "Values",
limits = vals$label,
values = c("blue", "forestgreen", "purple", "red"),
# Override the labels and set size to something sensible
guide = guide_legend(override.aes = list(label = vals$xintercept,
size = 3.88))
) +
labs(title = "relevant_title", y = "Distribution fors DLT values",
x = "DLT for the route: average values per batch") +
theme(plot.title = element_text(hjust = 0.5),
axis.title.x = element_text(colour = "darkblue"),
axis.text.x = element_text(face="plain", color="black",
size=10, angle=0),
axis.title.y = element_text(colour = "darkblue"),
axis.text.y = element_text(face="plain", color="black",
size=10, angle=0),
legend.position = c(.90, .80)
)+
labs(title="DLT values", y = "frequency", x = "days")+
scale_x_continuous(breaks = seq(0, max(data_to_plot$values), 1))
Created on 2021-01-08 by the reprex package (v0.3.0)

Issue filling histogram in ggplot

I am trying to fill with the same colour as the lines the data of the histograms shown in the figure below, I am using the following code. I have tried many things using fill, scale_fill_manual but without success. Any idea in how to correct this?
(stations = unique(DSF_moments$Station))
(station_cols = scales::hue_pal()(length(stations)))
(names(station_cols) = sort(stations))
for (i in 1:length(listDF2))
{
df1 <- as.data.frame(listDF2[[i]])
df1[is.na(df1)] <- 0
plot1 <- ggplot(df1, aes(x = Date, y = DailyMeanStreamflow, colour=Station)) +
geom_line(size = 1, show.legend = FALSE) +
geom_point(size=1.5, shape=21, fill="white",na.rm = TRUE, show.legend = FALSE)+
labs(title = "Daily Mean Streamflow", y = "Q[m3/s/Day]", x = "Date") +
theme(plot.title = element_text(size=16), axis.text.y = element_text(size=11), axis.text.x = element_text(size=11)) +
scale_color_manual(values = station_cols)
plot2 <- ggplot(df1, aes(DailyMeanStreamflow, colour=Station)) +
geom_histogram(show.legend = FALSE) +
labs(title = "Daily Mean Streamflow Histogram", y = "Frequency", x="Q[m3/s/Day]")+
scale_colour_manual(values = station_cols) + scale_fill_manual(values = station_cols)
(Monthly_Streamflow_Station <- df1 %>% group_by(month) %>% summarise(Monthly_Streamflow_Station = mean(DailyMeanStreamflow, na.rm=TRUE)))
plot3 <- ggplot(Monthly_Streamflow_Station, aes(x = month, y = Monthly_Streamflow_Station, colour=unique(df1$Station))) +
geom_line(size = 1, show.legend = FALSE) +
geom_point(size=1.5, shape=21, fill="white",na.rm = TRUE, show.legend = FALSE)+
labs(title = "Monthly Mean Streamflow", y = "Q[m3/s/Month]", x = "Month") +
theme(plot.title = element_text(size=16), axis.text.y = element_text(size=11), axis.text.x = element_text(size=11)) +
scale_x_continuous (breaks=seq(1,12,by=1)) +
scale_color_manual(values = station_cols)
plot4 <- ggplot(Monthly_Streamflow_Station, aes(Monthly_Streamflow_Station, colour=unique(df1$Station))) +
geom_histogram(show.legend = FALSE) +
labs(title = "Monthly Mean Streamflow Histogram", y = "Frequency", x="Q[m3/s/Month]") +
scale_colour_manual(values = station_cols)
(Annual_Streamflow_Station <- df1 %>% group_by(year) %>% summarise(Annual_Streamflow_Station = mean(DailyMeanStreamflow, na.rm=TRUE)))
plot5 <- ggplot(Annual_Streamflow_Station, aes(x = year, y = Annual_Streamflow_Station, colour=unique(df1$Station))) +
geom_line(size = 1, show.legend = FALSE) +
geom_point(size=1.5, shape=21, fill="white",na.rm = TRUE, show.legend = FALSE)+
labs(title = "Annual Mean Streamflow", y = "Q[m3/s/Year]", x = "Year") +
theme(plot.title = element_text(size=16), axis.text.y = element_text(size=11), axis.text.x = element_text(size=11)) +
scale_color_manual(values = station_cols)
plot6 <- ggplot(Annual_Streamflow_Station, aes(Annual_Streamflow_Station,colour=unique(df1$Station))) +
geom_histogram(show.legend = FALSE) +
labs(title = "Annual Mean Streamflow Histogram", y = "Frequency", x="Q[m3/s/Year]") +
scale_colour_manual(values = station_cols)
grid.arrange(grobs=list(plot1, plot2, plot3, plot4, plot5, plot6), ncol = 2, nrow = 3)
name5<- paste("Plots","_", siteNumber[i], ".png", sep="")
g <- arrangeGrob(plot1, plot2, plot3, plot4, plot5, plot6, ncol = 2, nrow = 3)
ggsave(g,filename = name5,width=22,height=11,units="in",dpi=500)
dev.off()
}
Try this change on your loop. No output produced due to lack of data. I have also changed scale_color_*() by scale_fill_*() where necesssary as said by great #aosmith that histograms require filling option enabled:
#Code
for (i in 1:length(listDF2))
{
df1 <- as.data.frame(listDF2[[i]])
df1[is.na(df1)] <- 0
plot1 <- ggplot(df1, aes(x = Date, y = DailyMeanStreamflow, colour=Station)) +
geom_line(size = 1, show.legend = FALSE) +
geom_point(size=1.5, shape=21, fill="white",na.rm = TRUE, show.legend = FALSE)+
labs(title = "Daily Mean Streamflow", y = "Q[m3/s/Day]", x = "Date") +
theme(plot.title = element_text(size=16), axis.text.y = element_text(size=11), axis.text.x = element_text(size=11)) +
scale_color_manual(values = station_cols)
plot2 <- ggplot(df1, aes(DailyMeanStreamflow, fill=Station)) +
geom_histogram(show.legend = FALSE) +
labs(title = "Daily Mean Streamflow Histogram", y = "Frequency", x="Q[m3/s/Day]")+
scale_fill_manual(values = station_cols)
(Monthly_Streamflow_Station <- df1 %>% group_by(month) %>% summarise(Monthly_Streamflow_Station = mean(DailyMeanStreamflow, na.rm=TRUE)))
plot3 <- ggplot(Monthly_Streamflow_Station, aes(x = month, y = Monthly_Streamflow_Station, colour=unique(df1$Station))) +
geom_line(size = 1, show.legend = FALSE) +
geom_point(size=1.5, shape=21, fill="white",na.rm = TRUE, show.legend = FALSE)+
labs(title = "Monthly Mean Streamflow", y = "Q[m3/s/Month]", x = "Month") +
theme(plot.title = element_text(size=16), axis.text.y = element_text(size=11), axis.text.x = element_text(size=11)) +
scale_x_continuous (breaks=seq(1,12,by=1)) +
scale_color_manual(values = station_cols)
plot4 <- ggplot(Monthly_Streamflow_Station,
aes(Monthly_Streamflow_Station,
fill=unique(df1$Station))) +
geom_histogram(show.legend = FALSE) +
labs(title = "Monthly Mean Streamflow Histogram", y = "Frequency", x="Q[m3/s/Month]") +
scale_fill_manual(values = station_cols)
(Annual_Streamflow_Station <- df1 %>% group_by(year) %>% summarise(Annual_Streamflow_Station = mean(DailyMeanStreamflow, na.rm=TRUE)))
plot5 <- ggplot(Annual_Streamflow_Station, aes(x = year, y = Annual_Streamflow_Station, colour=unique(df1$Station))) +
geom_line(size = 1, show.legend = FALSE) +
geom_point(size=1.5, shape=21, fill="white",na.rm = TRUE, show.legend = FALSE)+
labs(title = "Annual Mean Streamflow", y = "Q[m3/s/Year]", x = "Year") +
theme(plot.title = element_text(size=16), axis.text.y = element_text(size=11), axis.text.x = element_text(size=11)) +
scale_color_manual(values = station_cols)
plot6 <- ggplot(Annual_Streamflow_Station,
aes(Annual_Streamflow_Station,
fill=unique(df1$Station))) +
geom_histogram(show.legend = FALSE) +
labs(title = "Annual Mean Streamflow Histogram", y = "Frequency", x="Q[m3/s/Year]") +
scale_fill_manual(values = station_cols)
grid.arrange(grobs=list(plot1, plot2, plot3, plot4, plot5, plot6), ncol = 2, nrow = 3)
name5<- paste("Plots","_", siteNumber[i], ".png", sep="")
g <- arrangeGrob(plot1, plot2, plot3, plot4, plot5, plot6, ncol = 2, nrow = 3)
ggsave(g,filename = name5,width=22,height=11,units="in",dpi=500)
dev.off()
}

Missing Dots and Line Style in Figure Legend with ggplot2

After running the following commands:
Population <- c("A", "A", "A", "A", "B", "B", "B", "B")
Group <- rep(c("Experimental", "Experimental", "Control", "Control"), 2)
wave <- rep(c("Pretest", "Posttest"), 4)
outcome <- c(-.3, -.2, -.3, .4, -.6, -.5, -.6, .6)
ci <- rep(c(.13, .14), 4)
df <- data.frame(Population, Group, wave, outcome, ci)
df$wave <- factor(df$wave,levels = c('Pretest','Posttest'))
library(ggplot2)
pd <- position_dodge(0.1)
ggplot(df, aes(x = wave, y = outcome, color = interaction(Population, Group), shape = Group, group = interaction(Population, Group))) +
geom_errorbar(aes(ymin = outcome - ci, ymax = outcome + ci), width = .25, position = pd, size=.5) +
geom_line(aes(linetype = Group), position = pd, size=1, show.legend = FALSE) +
geom_point(position = pd, size = 3.5, fill = "white", stroke = 1.25, show.legend = FALSE) +
scale_color_manual(values = c("#000000", "#606060", "#000000", "#606060")) +
scale_shape_manual(values = c(23, 21)) +
coord_cartesian(xlim = c(1.4, 1.6), ylim = c(-.91, .91)) +
labs(title = "Outcomes by Population and Study Group", x = "Time", y = "Outcome\nLower scores denote fewer instances", color = "Population and Study Group") +
theme(plot.title = element_text(hjust = 0.5), axis.text.x = element_text(color = "black"), axis.text.y = element_text(color = "black"), panel.background = element_rect(fill = "#F0F0F0"))
I generate a figure that does not have dots symbols or correct line styles in the legend:
How can I:
add the dots shown in the figure itself into the legend and
have the legend lines reflect that some of dotted lines in the figure?
TYIA.
The simplest way is to create another variable that would reflect the interaction instead of creating it on the fly. If we build the plot step by step, this below gives the dots and errorbars:
library(ggplot2)
pd <- position_dodge(0.1)
df$grp = paste(df$Population,df$Group,sep=".")
g = ggplot(df, aes(x = wave, y = outcome, color = grp, shape = grp))+
geom_errorbar(aes(ymin = outcome - ci, ymax = outcome + ci), width = .25, position = pd, size=.5) +
geom_point(position = pd, size = 3.5, fill = "white", stroke = 1.25) +
scale_color_manual(values = c("#000000", "#000000","#606060", "#606060")) +
scale_shape_manual(values = c(23,21,23,21)) +
coord_cartesian(xlim = c(1.4, 1.6), ylim = c(-.91, .91)) +
labs(title = "Outcomes by Population and Study Group", x = "Time", y = "Outcome\nLower scores denote fewer instances") +
theme(plot.title = element_text(hjust = 0.5), axis.text.x = element_text(color = "black"),
axis.text.y = element_text(color = "black"), panel.background = element_rect(fill = "#F0F0F0"))
print(g)
Then add the line while specifying the legend:
g +
geom_line(inherit.aes=FALSE,aes(x = wave, y = outcome,group=grp,linetype=grp)) +
scale_linetype_manual(values=c("solid","dashed","solid","dashed"))

Customized Line Break for ggplot

I can create quality control charts with the qicharts2 package.
library(tidyverse)
library(qicharts2)
(plot1 <- qic(age,
data = tail(cabg, 100),
chart = 'i',
ylab = 'Years',
xlab = 'Patient #'
)
)
p1 <- plot1$data
Then I can customize the charts.
(plot2 <- ggplot(p1, aes(x, y)) +
geom_ribbon(ymin = p1$lcl, ymax = p1$ucl, fill = "black", alpha = 0.05) +
geom_line(color = "black", size = 1) +
geom_line(aes(x, cl)) +
geom_point(color = "black" , fill = "black", size = 2) +
geom_point(data = p1 %>% filter(sigma.signal == TRUE), color = "red", size = 2) +
ggtitle(label = NULL) +
labs(x = NULL, y = NULL) +
scale_y_continuous(breaks = seq(0, 100, by = 10)) +
coord_cartesian(ylim = c(0, 100)) +
theme_bw() +
theme(
text = element_text(size = 18),
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 0.6),
axis.text.y = NULL,
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
strip.text.x = element_text(size = 14, color = "black", angle = 0))
)
Using the part argument, in my qichart, causes it to split at the specified part point(s).
(plot3 <- qic(age,
data = tail(cabg, 100),
chart = 'i',
part = c(70, 85),
ylab = 'Years',
xlab = 'Patient #'
)
)
p3 <- plot3$data
What do I need to add to my customized ggplot2 syntax, below, to get it to part in the same manner? What I've got does everything, EXCEPT, it doesn't part like in the syntax directly above.
(plot4 <- ggplot(p3, aes(x, y)) +
geom_ribbon(ymin = p3$lcl, ymax = p3$ucl, fill = "black", alpha = 0.05) +
geom_line(color = "black", size = 1) +
geom_line(aes(x, cl)) +
geom_point(color = "black" , fill = "black", size = 2) +
geom_point(data = p3 %>% filter(sigma.signal == TRUE), color = "red", size = 2) +
ggtitle(label = NULL) +
labs(x = NULL, y = NULL) +
scale_y_continuous(breaks = seq(0, 100, by = 10)) +
coord_cartesian(ylim = c(0, 100)) +
theme_bw() +
theme(
text = element_text(size = 18),
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 0.6),
axis.text.y = NULL,
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
strip.text.x = element_text(size = 14, color = "black", angle = 0))
)
Is the following plot what you are looking for?
If so, what I used is group= in the aesthetics of geom_ribbon and geom_line
(plot4 <- ggplot(p3, aes(x, y)) +
geom_ribbon(aes(group=cut(p3$x,c(0,70,85,max(p3$x)))),ymin = p3$lcl, ymax = p3$ucl, fill = "black", alpha = 0.05) +
geom_line(color = "black", size = 1, aes(group=cut(p3$x,c(0,70,85,max(p3$x))))) +
geom_line(aes(x, cl, group=cut(p3$x,c(0,70,85,max(p3$x))))) +
geom_point(color = "black" , fill = "black", size = 2) +
geom_point(data = p3 %>% filter(sigma.signal == TRUE), color = "red", size = 2) +
ggtitle(label = NULL) +
labs(x = NULL, y = NULL) +
scale_y_continuous(breaks = seq(0, 100, by = 10)) +
coord_cartesian(ylim = c(0, 100)) +
theme_bw() +
theme(
text = element_text(size = 18),
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 0.6),
axis.text.y = NULL,
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
strip.text.x = element_text(size = 14, color = "black", angle = 0)))

ggplot2: label n observations for alpha on stacked bars

I have a df as it follows:
fruit <- data.frame(Sample=1:100,
Fruit=c(rep("Apple", 10), rep("Strawberry", 25), rep("Grape", 20),
rep("Watermelon", 15), rep("Lime", 11), rep("Blueberry", 10),
rep("Plum", 9)),
Color=c(rep("Red", 30), rep("Green", 45),
rep("Blue", 25)),
Ripe=c(rep(c(T, F), 50)))+
fruit$Fruit <- factor(fruit$Fruit, unique(fruit$Fruit))+
fruit$Color <- factor(fruit$Color, unique(fruit$Color))
Then, I've plotted the bar graph:
foo <- aggregate(Sample ~ Color, data = fruit, FUN = length)
library(ggplot2)
ggplot(fruit, aes(Color, fill = Color, alpha = Ripe)) +
geom_bar(color = "black") +
geom_text(data = foo, aes(label = Sample, y = Sample), alpha = "1", vjust = -1)
scale_alpha_discrete(range = c(1, 0.6)) +
theme(axis.title.x = element_blank(),
axis.text.x = element_blank(),
axis.ticks.x = element_blank()) +
guides(fill = guide_legend(override.aes = list(colour = NA)))
With the command above I was able to create the following bar-graph:
So...I was able to put the total number of observations for each Color above each bar...but I don't this....rather, I'm wonder how can I put the total n of observation for TRUE in each color bar instead. In this case it would be one n observation for each bar, with one above the above the TRUE bar for the TRUE n observation for that particular Color...
You can use calculating power of stat in ggplot2
ggplot(fruit, aes(Color, fill = Color, alpha = Ripe)) +
geom_bar() +
geom_text(stat = "count", aes(y = ..count.., label = ..count..),
position = "stack", show.legend = FALSE) +
scale_alpha_discrete(range = c(1, 0.6)) +
theme(axis.title.x = element_blank(),
axis.text.x = element_blank(),
axis.ticks.x = element_blank()) +
guides(fill = guide_legend(override.aes = list(colour = NA)))

Resources