r - 使地铁图包括 ggplot2 r 中的 102 个主题
问题描述
我在这个问题的答案中使用了代码,但正在努力解决如何最好地操作图表以使其适合地铁图中的 100 个唯一 dict 条目,而不会完全弄乱边缘上的 dict 词条目。
我测试了输入地铁图的不同数量的单词,发现它不能包含超过 25 个单词。
我有数据:
structure(list(dict = c("apple", "apple", "apple",
"mandarin", "mandarin", "mandarin", "orange", "orange", "orange", "pear"),
name = c("freq_ongov", "freq_onindiv", "freq_onmedia", "freq_ongov",
"freq_onindiv", "freq_onmedia", "freq_ongov", "freq_onindiv",
"freq_onmedia", "freq_ongov"), value = c(0, 87, 63, 0, 44,
20, 3, 27, 25, 0), rank = c(26, 85, 70, 26, 61, 42.5, 86,
47, 48, 26)), row.names = c(NA, -10L), groups = structure(list(
name = c("freq_ongov", "freq_onindiv", "freq_onmedia"), .rows = structure(list(
c(1L, 4L, 7L, 10L), c(2L, 5L, 8L), c(3L, 6L, 9L)), ptype = integer(0), class = c("vctrs_list_of",
"vctrs_vctr", "list"))), row.names = c(NA, 3L), class = c("tbl_df",
"tbl", "data.frame"), .drop = TRUE), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"))
但是我想在以下代码中包含此数据中的 100 行:
leftlabels <- df$dict[df$name == "freq_ongov"]
leftlabels <- leftlabels[order(df$rank[df$name == "freq_ongov"])]
rightlabels <- df$dict[df$name == "freq_onmedia"]
rightlabels <- rightlabels[order(df$rank[df$name == "freq_onmedia"])]
ggplot(df, aes(name, rank, color = dict, group = dict)) +
geom_line(size = 4) +
geom_point(shape = 21, fill = "white", size = 4) +
scale_y_continuous(breaks = seq(max(df$rank)), labels = leftlabels,
sec.axis = sec_axis(~., breaks = seq(max(df$rank)),
labels = rightlabels)) +
scale_x_discrete(expand = c(0.01, 0)) +
guides(color = guide_none()) +
coord_cartesian(clip = "off") +
theme(axis.ticks.length.y = unit(0, "points"))
我尝试更改y.int
y 轴的宽度和宽度以适合 100 个单词,但这只会使 y 轴更长,而不会更改 y 轴上每个单词标签之间的间距,因此所有单词都被挤在一起。有什么建议么?
解决方案
推荐阅读
- c++ - 计算第一个和最后一个元素的绝对差小于<= K的子序列
- python - 有没有一种 Python 方法可以从 URL 链接的数据集中选择只有 200 个状态码的链接?
- python - 如何在 Pycharm 2 中的广告中从同一项目下的 github(相互依赖)克隆存储库
- ef-code-first - 在 Postman 中获得响应以进行更新
- flutter - Flutter中有哪些不同的构建器小部件(Future Builder、Stream Builder、Layout builder、Listview Builder)。
- php - 如何登录到两个不同的 codeigniter 项目
- php - 如何使多个 HTML 表单的单个提交按钮将每个表条目显示为行中的新表单?
- python - 如果“x”出现在一列中并且“y”出现在另一列中,则计数
- python - 在使用键工作时搜索字典键值的时间复杂度是多少 *in*
- javascript - 如何从 javascript 类方法返回一个值?