我想在橫軸上顯示月份(縮寫形式),并將相應的年份打印一次。我知道如何顯示月份年份:在此處輸入圖片說明一年中不必要的重復會打亂標簽。相反,我想要這樣的東西:在此處輸入圖片說明除了年份將 在月份下方打印。我在軸標簽上方打印了年份,因為這是我能做的最好的事情。這是對annotate()功能的限制,如果該功能位于繪圖區(qū)域之外,則會受到限制。我知道基于的可能解決方法annotate_custom(),但是我無法使它們與日期對象一起使用(我沒有嘗試將日期轉(zhuǎn)換為數(shù)字并再次返回到日期,因為它看起來比希望的要復雜得多)我想知道是否dup_axis()可以為此目的劫持新產(chǎn)品。如果可以將重復的軸發(fā)送到面板的另一側(cè),而不是將重復的軸發(fā)送到面板的另一側(cè),則可能只需要設(shè)置一個panel.grid.major消隱的軸并將標簽設(shè)置為%b,另一個軸將panel.grid.minor消隱,標簽設(shè)置為%Y。(另一個挑戰(zhàn)是,年份標簽將改為10月而不是1月)這些問題是相關(guān)的。但是,據(jù)我所知,該annotate_custom()功能textGrob()與日期不能很好地配合使用。我如何在ggplot2中的x軸下方添加注釋在ggplot2生成的情節(jié)下面顯示文本數(shù)據(jù)和基本代碼如下: library("ggplot2") library("scales") ggplot(data = df, aes(x = Date, y = value)) + geom_line() + scale_x_date(date_breaks = "2 month", date_minor_breaks = "1 month", labels = date_format("%b %Y")) + xlab(NULL) ggplot(data = df, aes(x = Date, y = value)) + geom_line() + scale_x_date(date_minor_breaks = "2 month", labels = date_format("%b")) + annotate(geom = "text", x = as.Date("1719-10-01"), y = 0, label = "1719") + annotate(geom = "text", x = as.Date("1720-10-01"), y = 0, label = "1720") + xlab(NULL) # data df <- structure(list(Date = structure(c(-91455, -91454, -91453, -91452, -91451, -91450, -91448, -91447, -91446, -91445, -91444, -91443, -91441, -91440, -91439, -91438, -91437, -91436, -91434, -91433, -91431, -91430, -91429, -91427, -91426, -91425, -91424, -91423, -91422, -91420, -91419, -91418, -91417, -91416, -91415, -91413, -91412, -91411, -91410, -91409, -91408, -91406, -91405, -91404, -91403, -91402, -91401, -91399, -91398, -91397, -91396, -91395, -91394, -91392, -91391, -91390, -91389, -91388, -91387, -91385, -91384, -91382, -91381, -91380, -91379, -91377, -91376, -91375, -91374, -91373, -91372, -91371, -91370, -91369, -91368, -91367, -91366, -91364, -91363, -91362, -91361, -91360, -91359, -91357, -91356, -91355, -91354, -91353, -91352, -91350, -91349, -91348, -91347, -91346, -91345, -91343, -91342, -91341, -91340, -91339,
- 3 回答
- 0 關(guān)注
- 696 瀏覽
添加回答
舉報
0/150
提交
取消