我想转换坐标(而不是比例/值),以便y变量(翻转到x)的间隔更好。我认为这将是coord_trans(y="log10")
或coord_trans(y="log2")
或其他什么,但这似乎不起作用。
library(ggplot2)
library(scales)
dat <- structure(list(median=c(2893, 0, 907.5, 1315, 0, 84, 98, 953,
0, 0, 1349, 17.5, 48.5, 7, 28, 18, 14, 37.5, 0, 383, 220.5, 49,
86.5, 816.5, 38, 41, 38, 1302, 14, 0, 1304, 754, 424.5, 0, 35.5,
28, 32, 0, 39),
name = c("name 1", "name 2", "name 3", "name 4",
"name 5", "name 6", "name 7", "name 8", "name 9", "name 10",
"name 11", "name 12", "name 13", "name 14", "name 15", "name 16",
"name 17", "name 18", "name 19", "name 20", "name 21", "name 22",
"name 23", "name 24", "name 25", "name 26", "name 27", "name 28",
"name 29", "name 30", "name 31", "name 32", "name 33", "name 34",
"name 35", "name 36", "name 37", "name 38", "name 39")),
.Names = c("median", "name"), row.names = c(NA, -39L), class = "data.frame")
dat = transform(dat, name = reorder(name, median))
ggplot(dat) +
geom_point(aes(y=median, x=name)) +
#coord_trans(y="log10") +
coord_flip() +
theme_bw() +
theme(
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
axis.line = element_line(color = 'black'),
panel.background = element_blank(),
axis.title.y = element_blank())
我不想重新调整值:
ggplot(dat) +
geom_point(aes(y=median, x=name)) +
scale_y_log10() +
coord_flip() +
theme_bw() +
theme(
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
axis.line = element_line(color = 'black'),
panel.background = element_blank(),
axis.title.y = element_blank())
答案 0 :(得分:2)
好了,现在我明白了你的问题,这里的答案是希望它能帮助别人。
首先,coord_*
函数无法堆叠 - 它们会相互覆盖。因此,使用它的方式,coord_flip(...)
会覆盖coord_trans(...)
,而您却看不到任何转化。
要根据线性间距获得带有刻度标签的log10间距,使用翻转坐标,您可以使用breaks=...
参数scale_*
,如下所示:
ggplot(dat) +
geom_point(aes(y=median, x=name)) +
scale_y_log10(breaks=1000*(1:3)) + # note use of breaks=...
coord_flip() +
theme_bw() +
theme(
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
axis.line = element_line(color = 'black'),
panel.background = element_blank(),
axis.title.y = element_blank())