How can I make the lines thicker without adding geom_line
ggplot(df, aes(x=c, y=d, colour=group)) +
geom_point()+
geom_smooth( method=lm,se=FALSE, fullrange=TRUE)
Thank you
Related
I am trying to produce a ggplot that shows the histogram of the data as well as two density curves in which one has no adjust value and the other one has.
I tried the following code:
ggplot(df, aes_string(x=value))+
geom_histogram(aes(y=..density..), colour="grey", fill="grey", alpha=.3)+
geom_density(colour="red", fill="red", alpha=.3)+
stat_density(bw="SJ", alpha=0)+
geom_density(colour="blue", fill="blue", alpha=.3)+
stat_density(bw="SJ", adjust=5, alpha=0)+
theme_bw()
But this produces this graph with both curves overlapping 100%...
The .txt dataframe used is on my google drive
Thanks in advance!
Does adding a specific adjust argument to geom_density not do what you want?
ggplot(df, aes(x=value))+
geom_histogram(aes(y=..density..), colour="grey", fill="grey", alpha=.3)+
geom_density(colour="red", fill="red", alpha=.3, adjust = 1)+
geom_density(colour="blue", fill="blue", alpha=.3, adjust = 2)+
theme_bw()
I have the following code:
ggplot(iris, aes(x=Species, y=Sepal.Length)) +
stat_summary(fun.y=mean, geom='point', size=2, fill='white')
I know there are probably other ways of plotting this mean using the iris data. For my own data, though, it is the only way.
PROBLEM: the code above doesn't give white-filled points, but solid black points. Is there ar way to set the fill-colour when using the stat_summary argument?
Thanks!
Either use color instead of fill
ggplot(iris, aes(x=Species, y=Sepal.Length)) +
stat_summary(fun.y=mean, geom='point', size=2, color='white')
or use a symbol shape that has a fill and a border color
ggplot(iris, aes(x=Species, y=Sepal.Length)) +
stat_summary(fun.y=mean, geom='point', size=2, shape=21, fill="blue", color="red")
data=data.frame(x=rep(0:9, each=2))
ggplot(data, aes(x=factor(x))) + geom_bar(alpha=0.5) +
geom_point(data=data.frame(x=0:10, y=2), aes(x=factor(x), y=y), alpha=0.5)
ggplot(data, aes(x=factor(x))) + geom_bar(alpha=0.5) +
geom_point(data=data.frame(x=0:10, y=2), aes(x=factor(x), y=y), alpha=0.5) +
scale_x_discrete(limits=0:10)
Also, do I have to factor given x is integer so it is discrete already?
Wrong order
Wrong x axis label.
ggplot(data, aes(x=x)) + geom_bar(alpha=0.5) + scale_x_discrete(limits=0:10) +
geom_point(data=data.frame(x=0:10, y=2), aes(x=x, y=y), alpha=0.5)
You can force a discrete scale to get what you want. It is odd how when you mix geom_point() and geom_bar() ggplot starts ordering things in unexpected ways.
How can I avoid the grey shading of the plot area that occurs when plotting the following data?
df <-data.frame(x = c(0,0.2,0.5), y = c(0.6,0.7,0.9))
p <-ggplot(df, aes(x, y, ymin=0, ymax=1, xmin=0, xmax=1))
p <- p + geom_point(alpha=2/10, shape=21,
fill="blue", colour="black", size=5)
p
So fine up until this point but then adding a line equation using geom_smooth causes part of the background to become grey.
p <- p + geom_smooth(method="lm", se=FALSE, formula=y~x, colour="black")
p
Any suggestions on how to avoid this? Thanks.
Add fill=NA to your geom_smooth call:
p + geom_smooth(method="lm", se=FALSE, formula=y~x,colour="black",fill=NA)
From Plot vectors of different length with ggplot2, I've got my plot with lines.
ggplot(plotData, aes(x, y, label=label, group=label)) + geom_line() + stat_smooth()
But this smooths one line each. How do I smooth over all data points?
ggplot(plotData, aes(x, y, label=label, group=label)) +
geom_line() +
geom_smooth(aes(group = 1))
should do it. The idea here is to provide a new group aesthetic so that the fitted smoother is based on all the data, not the group = label aesthetic.
Following the example from #Andrie's Answer the modification I propose would be:
ggplot(plotData, aes(x, y, label=label, group=label)) +
geom_text() +
geom_smooth(aes(group = 1))
which would produce: