![](/img/trans.png)
[英]How to remove 0s from histogram using ggplot in R but still include them in the calculation of percent/count?
[英]How to remove center of range from ggplot histogram in R
我使用以下代碼生成了直方圖:
# Load Data
file <- "SharedData.csv"
data <- read.csv(file,header = TRUE,sep = ",")
## Bin Levels
data$xLevel <- cut(data$xLevel,
breaks = quantile(data$xLevel,(0:5)/5),
labels = paste("Quant",1:5,sep = "."),
include.lowest = TRUE,ordered_result = TRUE)
# Histogram
g <- ggplot(data, aes(x=xTime,color = xLevel)) +
geom_histogram(aes(y=..density..),
binwidth=100)
g
如何使用x軸(從0-300到1500-2400,但不包括300-1500)創建上述直方圖? 這里的單位是軍事時間。
數據: https : //www.dropbox.com/s/e5gaym7dhefs04e/SharedData.csv?dl = 0
根據https://groups.google.com/forum/#!topic/ggplot2/jSrL_FnS8kc並使用ggplot2,我可以在軸上插入一個中斷嗎? 這似乎是不可能的。 您可以改為繪制2個圖形
首先創建一個新列,將數據分為兩部分
data$Block <- ifelse(data$xTime <=500, "A", "B")
然后繪制圖形
library(scales)
# Histogram
g <- ggplot(data, aes(x=xTime,color = xLevel)) +
geom_histogram(aes(y=..density..),
binwidth=100) + facet_grid(.~Block, scales = "free_x")
g
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.