第一个可重复的例子:
数据:
grid_tbl <- bind_cols(x = seq(from = -10, to = 10, by = 0.05),
y = seq(from = -10, to = 10, by = 0.05))
sine_points_vec <- map(grid_tbl$x, sinpi) %>% unlist()
sine_plot_tbl <- bind_cols(grid_tbl$x, sine_points_vec) %>% rename(x = `...1`, y = `...2`)
字符串
剧情:
sine_plot_tbl %>%
select(y,x) %>%
rename(y = x, x = y) %>%
ggplot(aes(x = y, y = x)) +
coord_fixed(ratio = 0.8) +
# coord_flip() +
geom_line(color = "red") +
geom_hline(yintercept = 0, color = "blue") +
labs(
title = "Inverse Sine Relation Plot",
caption = "Vertical line passes through curve at many points"
)
型
目标:
我正在寻找一种方法来压缩X轴的固定百分比,以改变绘制曲线的外观,使曲线的峰值更平坦。
例如,在发布的代码中,coord_fixed(ratio = 0.8)产生了期望的外观,但是如果我取消注解下一行以翻转坐标,则扁平化被丢弃。我得到这样的消息:
- 坐标系已存在。正在添加新坐标系,该坐标系将替换现有坐标系。*
我并不想转换生成曲线的值,只是想改变曲线的外观。如果你在coord_fixed()函数和coord_flip()函数之间交换注解标记,你会看到挑战。
我尝试在ggplot中添加coord_fixed(),我希望曲线的外观变平。
实际发生的是,随后的coord_flip()函数覆盖了它。
2条答案
按热度按时间xdnvmnnf1#
使用扩展来扩大所示x轴的范围的轻微变化,这里使两侧的宽度为数据的5倍。
字符串
的数据
kqqjbcuj2#
每个图只能有一个
coord
层。但是,代替coord_flip
,你可以切换x
和y
,并在geom_line
中使用orientation="y"
:字符串
的数据