问题:如何利用n\
或类似方法在用x-axis label
编写的paste0
中创建两条文本行
我有
如您所见,我当前在x-axis
上有两条独立的行,如当前用labels = paste0("LN: \nLND: ", paste0(seq(0,80,5))))
编写的。
我希望从seq(0,80,5)
产生的数值出现在两行中,但%
写在文本之一的后面。
预期输出:
奖金问题:是否可以手动右/左/居中对齐我要在
x-axis label
上创建的两条文本行?
撰写者
ggplot(p, aes(x=value, y=os.neck, color=name_new, fill=name_new)) +
geom_point(size=2, shape=21, stroke=1, fill="white") +
geom_quantile(quantiles=.5, size=1.3) +
scale_x_continuous(breaks = seq(0,80,5),
name="Lymph nodal yield",
labels = paste0("LN: \nLND: ", paste0(seq(0,80,5)))) +
scale_y_continuous(breaks = seq(0,180,20),
name="Months to death")
数据样本p
p <- structure(list(value = c(22.2, 18, 9.1, 11, 14, 15, 9, 6, 3,
25, 16, 4, 6, 10, 13, 12.1, 33, 16, 6, 9, 4.3, 23, 9, 8, 13,
5, 30, 25, 33.3, 3, 9, 33.3, 9, 12, 7, 38, 60, 5, 71.4, 7, 15,
25, 4, 16.7, 6, 15, 11.1, 9, 8, 42.9, 7, 4, 16.7, 6, 10, 10,
62.5, 8, 25, 4, 11.1, 9, 10, 14, 14, 3, 4, 50, 6, 6, 20, 33.3,
3, 7.7, 26, 13, 7.7, 13, 13, 13, 3, 7, 16.7, 6, 5, 20, 10, 15,
29, 7, 6, 11, 11.8, 17, 71.4, 14, 33.3, 18, 22, 9), os.neck = c(11.5,
11.5, 74.38, 74.38, 17.02, 7.89, 96.03, 40.48, 17.74, 14.65,
14.65, 62.46, 12.55, 9.92, 26.05, 45.47, 45.47, 17.38, 39.72,
51.45, 8.61, 8.61, 76.98, 67.09, 94.79, 72.15, 93.93, 17.05,
12.48, 12.48, 91.6, 15.87, 15.87, 11.04, 67.22, 67.02, 8.94,
8.94, 6.6, 6.6, 5.09, 10.68, 10.68, 17.15, 17.15, 0.07, 5.19,
5.19, 40.77, 0.2, 0.2, 170.88, 5.55, 5.55, 1.61, 1.61, 38.28,
38.28, 10.58, 10.58, 32.99, 32.99, 110.98, 103.69, 122.32, 14.78,
42.74, 4.04, 4.04, 8.28, 84.96, 11.7, 11.7, 49.97, 49.97, 120.48,
52.6, 52.6, 71.26, 16.3, 100.14, 55.03, 6.51, 6.51, 89.89, 51.71,
51.71, 24.97, 55.66, 21.91, 81.48, 30.92, 1.58, 1.58, 7.52, 7.52,
30.75, 30.75, 3.45, 19.22), name_new = structure(c(3L, 2L, 3L,
2L, 1L, 1L, 1L, 1L, 1L, 3L, 2L, 1L, 1L, 1L, 1L, 3L, 2L, 1L, 1L,
1L, 3L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 1L,
1L, 3L, 2L, 3L, 2L, 1L, 3L, 2L, 3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L,
1L, 3L, 2L, 3L, 2L, 3L, 2L, 3L, 2L, 3L, 2L, 1L, 1L, 1L, 1L, 1L,
3L, 2L, 1L, 1L, 3L, 2L, 3L, 2L, 1L, 3L, 2L, 1L, 1L, 1L, 1L, 3L,
2L, 1L, 3L, 2L, 1L, 1L, 1L, 1L, 1L, 3L, 2L, 3L, 2L, 3L, 2L, 1L,
1L), .Label = c("n_fjernet0", "n_fjernet1", "lnd1"), class = "factor")), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -100L))
我对您的paste0
语句摆弄了一点,对我来说,最简单的解决方案是重复paste0(seq(0,80,5))
以得到所需的结果:
您的人可以用paste0()
这样来做:
这是一个技巧,但我似乎可以做你想做的事(?)。不幸的是,我认为所有的文字都挤在旅馆里看起来并不好。