簡體   English   中英

如何在R / ggplot2中創建數據的階梯圖?

[英]How to create a stair step plot of data in R/ggplot2?

我有一個點列表,我想繪制它們並用階梯連接它們,如以下屏幕截圖所示。

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)")

我如何用ggplot2達到相同的目的?

在此處輸入圖片說明

這適用於qplot():

qplot(seq_along(df2$mean.energy), df2$mean.energy, geom="step")

與ggplot()語法相同:

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()

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM