這可能是一件很明顯,我的思念,但考慮到以下GGPLOT2直方圖:顯示標籤在各條
ggplot(diamonds, aes(carat)) +
geom_histogram(color="white") +
theme_light()
我想要的標籤(例如1)柱狀圖的開始在酒吧的開始或結束時,不在中點。
這可能是一件很明顯,我的思念,但考慮到以下GGPLOT2直方圖:顯示標籤在各條
ggplot(diamonds, aes(carat)) +
geom_histogram(color="white") +
theme_light()
我想要的標籤(例如1)柱狀圖的開始在酒吧的開始或結束時,不在中點。
它可以自定義每個區間的邊界,通過geom_histogram
的breaks
參數。如果您想要在紙盒的開始或結束標籤,那麼您只需確保標籤的breaks
具有紙盒寬度的倍數(或切割中的步驟):
cut_breaks = seq(0, 5, 0.2)
lab_breaks = seq(0, 5, 1) # make sure 1 here is a multiple of 0.2
ggplot(diamonds, aes(carat)) +
geom_histogram(color="white", breaks = cut_breaks) +
scale_x_continuous(breaks = lab_breaks) +
theme_light()
下面是一組不同的休息:
cut_breaks = seq(0, 5, 0.2)
lab_breaks = seq(0, 5, 0.6) # 0.6 is a multiple of 0.2
ggplot(diamonds, aes(carat)) +
geom_histogram(color="white", breaks = cut_breaks) +
scale_x_continuous(breaks = lab_breaks) +
theme_light()
如果您添加一條帶有以下放置說明的文本行,它會將它們放到您想要它們的位置,但您需要使用要打印的標籤填充該零件。
ggplot(diamonds, aes(carat, label =)) +
geom_histogram(color="white") +
theme_light()+
geom_text(aes(y = y + 0.05), vjust = 0)