Reputation: 734
I draw a frequency plot with geom_freqpoly :
ggplot(all,aes(x=time,color=type))
+geom_freqpoly(size=1.3,binwidth=2160)
+theme_bw()+scale_x_datetime(breaks = date_breaks("2 hours"), labels=date_format("%H:%M"))
I want to add point to the plot like:
How to do this? Thank you very much.
Upvotes: 0
Views: 706
Reputation: 1
The above worked for me, though it doesn't correspond to the appropriate values and thus messed up my axes.
Here is my code:
Data_Freq.Poly.1 <-
ggplot(Data, aes(x = Data)) +
labs(x = "Data", y = "Frequency", title = "Frequency Polygon of the Data Provided") +
geom_freqpoly(center = 67.5,
bins = 7,
colour = "black") +
geom_point(stat = "bin",
aes(y = ..count..),
bins = 7) +
scale_x_continuous(breaks = seq(39.5, 95.5, by = 8)) +
scale_y_continuous(breaks = c(0:12)) +
theme_classic()
theme(plot.title = element_text(hjust = 0.5,
face = "bold",
size = 16))
Data_Freq.Poly.1
Here is my graph: [Why are the points not on the line?][1]
Here is what it should look like: I've had to add the points manually on my tablet
Upvotes: 0
Reputation: 892
I had the same question and figured out that we can tell geom_point() to use the same bins and counts as geom_freqpoly() like this:
set.seed(8675309)
df <- data.frame(x=rnorm(100))
ggplot(data=df, aes(x=x)) +
geom_freqpoly(binwidth=0.25) +
geom_point(stat="bin", aes(y=..count..), binwidth=0.25)
I hope this helps!
Upvotes: 2