Overplotting from 2 data frames in ggplot2 bar plot + stacked bar
Tag : r , By : Helpful Dude
Date : March 29 2020, 07:55 AM
this will help I'm not completely sure what you're asking, but does this give what you want? yield <- rbind(transform(pure, mix = Var), transform(mixt, mix = 'Mixed'))
ggplot(yield, aes(x=mix, y=mean, fill=Var)) +
geom_bar(stat="identity")
ggplot() +
geom_bar(data = transform(pure, mix = Var), aes(x=mix, y=mean, fill=Var), stat="identity") +
geom_bar(data = transform(mixt, mix = 'Mixed'), aes(x=mix, y=mean, fill=Var), stat="identity")
ggplot() +
mapply(function(x, type)
geom_bar(data = transform(x, mix = type),
aes(x=mix, y=mean, fill=Var), stat="identity"),
list(pure, mixt),
list(pure$Var, 'Mixed'))
|
ggplot reorder stacked bar plot based on values in data frame
Tag : r , By : Marcos de Carvalho
Date : March 29 2020, 07:55 AM
wish helps you I am making stacked bar plots with ggplot2 in R with specific bar ordering about the y-axis. , Try: ggplot(d, aes(x = Day, y = Length)) +
geom_bar(aes(fill = Amount, order = -Location), stat = "identity")
|
How to plot many data frames on the same graph with ggplot
Tag : r , By : Vlad Sirenko
Date : March 29 2020, 07:55 AM
I wish this helpful for you I would combine the data.frame into one large data.frame, add an id column, and then plot with ggplot. Lots of ways to do this, here is one: newDF <- do.call(rbind, list.df)
newDF$id <- factor(rep(1:length(df.list), each = sapply(df.list, nrow)))
g <- geom(newDF, aes(x = dX, y = dY, colour = id)
g <- g + geom_line()
print(g)
|
ggplot legends when plot is built from two data frames
Date : March 29 2020, 07:55 AM
I wish did fix the issue. You need to use one of the symbols that takes a fill (pch = 21:25). You then need to use override.aes to get the legend right. I've moved shared data and aes into the ggplot command. ggplot(data=df, aes(x=x, y=y)) +
geom_point(aes(color="Weekly Forecast"), shape=16, size = 5) +
geom_line(color="red", size=1) +
geom_point(data=df2, aes(color="Main Forecast"), shape=21, fill = "white", size = 5) +
scale_color_manual("Legend Title", limits=c("Weekly Forecast", "Main Forecast"), values = c("red","red")) +
guides(colour = guide_legend(override.aes = list(pch = c(16, 21), fill = c("red", "white"))))
ggplot(data=df, aes(x=x, y=y)) +
geom_line(aes(color="Main Forecast"), size=1) +
geom_point(aes(color="Weekly Forecast", fill="Weekly Forecast"), shape=21, size = 5) +
geom_point(data=df2, aes(color="Main Forecast", fill="Main Forecast"), shape=21, size = 5) +
scale_color_manual(name="", values = c("red","red")) +
scale_fill_manual(name="", values=c("white","red"))
|
Workflow to convert data used for stacked bar ggplot to one usable for stacked percentage plot
Date : March 29 2020, 07:55 AM
I wish this helpful for you I have the following dataset: dat = aggregate(list(value = 1:NROW(df)), df[c("age_group", "Gender")], length)
dat$proportion = ave(dat$value, dat$age_group, FUN = function(x) x/sum(x))
ggplot(dat, aes(x = age_group, y = proportion, fill = Gender)) +
geom_col() +
coord_flip()
|