【问题标题】:Change ticks position inwards in ggplot在ggplot中向内更改刻度位置
【发布时间】:2016-05-03 15:28:42
【问题描述】:

我想将 ggplot 图中刻度的位置更改为向内位置。 axis.ticks.margin 已弃用,因此我尝试使用 axis.text 功能但无法做到。谁能帮帮我?

这是一个示例数据集df

df<- structure(list(X1 = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 
29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41), X2 = c(0, 
10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 
150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250, 260, 270, 
280, 290, 300, 310, 320, 330, 340, 350, 360, 370, 380, 390, 400
)), .Names = c("X1", "X2"), row.names = c(NA, -41L), class = "data.frame")

以下是我目前尝试过的:

library(ggplot2)
ggplot(df, aes(x=Age, y=GPP)) + 
  geom_point()+
  theme(panel.grid = element_blank(),
        element_text(hjust=seq(from=0,to=1,length.out=6)),
        axis.text.y = element_text(margin=margin(5,5,10,5,"pt")))

【问题讨论】:

标签: r ggplot2 axis


【解决方案1】:
ggplot(df, aes(x=Age, y=GPP)) + 
  geom_point()+
  theme(panel.grid = element_blank(),
axis.ticks.length=unit(-0.25, "cm"), axis.text.x = element_text(margin=unit(c(0.5,0.5,0.5,0.5), "cm")), axis.text.y = element_text(margin=unit(c(0.5,0.5,0.5,0.5), "cm")))

【讨论】:

    猜你喜欢
    • 2015-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多