【问题标题】:A x-axis at top of ggplot with different labelsggplot 顶部带有不同标签的 x 轴
【发布时间】:2016-02-02 17:29:25
【问题描述】:

我想在绘图顶部添加一些与 x 轴对齐的标签。如何将 cm3 的位移添加到该图的顶部,以便底部有立方英寸,顶部有立方厘米?我应该用注释来做吗?刻度线呢?我意识到在这种情况下这会产生一个丑陋的图表。 [为清楚起见进行了编辑。]

# Calculate displacement in cm3 -- add this to top of plot 
# above 100, 200, 300, 400 ticks and labels for cubic inches on bottom
cm3.lab <- seq(100,400,100) * 16.3871
p <- ggplot(mtcars, aes(disp, mpg))
p + geom_point(size=5) + xlab("Cubic inches")
p

【问题讨论】:

  • p + geom_point(size=5) + xlab("立方英寸") 好像给你想要的

标签: r ggplot2


【解决方案1】:

您可以使用scale_x_continuous 更好地控制标签和刻度线:

p + geom_point(size=5) + scale_x_continuous(name="Displacement in cubic centimeters", breaks = c(100, 200, 300, 400), labels=c("100" = "100", "200" = "200", "300" = "300", "400" = "400"));

更多选项请见?scale_x_continuous

注意:立方厘米和立方英寸不是一回事。一定要选对的!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-16
    相关资源
    最近更新 更多