Reputation: 234
I have a list of points and I'd like to plot them and connect them with stair steps, like the following screenshot.
df <- read.table('out.dat')
df <- df[df$V1>0,]
st <- stats.bin(x=df$V1, y=df$V2, N=100)
df2 <- as.data.frame(st$stats["mean",])
names(df2) <- c('mean.energy')
plot(df2$mean.energy, type="s",
xlab="Off-axis distance (mm)", ylab="Mean Energy (MeV)")
How could I achieve the same with ggplot2 ?
Upvotes: 2
Views: 6471
Reputation: 234
This works with qplot():
qplot(seq_along(df2$mean.energy), df2$mean.energy, geom="step")
The same with the ggplot() syntax:
ggplot(df2) +
geom_step(aes(x=seq_along(df2$mean.energy), y=df2$mean.energy)) +
xlab("Off-axis distance (mm)") +
ylab("Mean Energy (MeV)") + theme_bw()
Upvotes: 5