我正在尝试反转 Y 轴的值。我基本上希望 Y 轴随着上升而减小,因此应该是 16,而不是 24。我该怎么做?
ggplot(data=data_diff, aes(Sum.of.Diff, Sum.of.Against.Total) +
geom_point(alpha=1) +
ggtitle("Data Diff") +
geom_label_repel(data=subset(data_diff, Sum.of.Against.Total> 0 | Sum.of.Diff > 0 | Sum.of.Diff < 0), aes(label=Name), box.padding = 0.5, point.padding = .11, segment.color = 'black') +
xlab("Sum of Diff") + ylab("Sum of Against Stats Total")
Run Code Online (Sandbox Code Playgroud)
示例图:

这是我的数据集:
Name Sum.of.Against.Total Sum.of.Diff
1 Aurorus 26.00 185.66
2 Parasect 25.00 155.66
3 Leavanny 25.00 115.66
4 Abomasnow 25.00 115.66
5 Frosmoth 24.50 115.66
6 Rhyperior 24.25 115.66
7 Golem 24.25 115.66
8 Exeggutor 24.00 115.66
9 Weavile 23.50 115.66
10 Flapple 23.25 115.66
11 Appletun 23.25 115.66
12 Alolan Exeggutor 23.25 82.66
13 Tyranitar 23.00 70.66
Run Code Online (Sandbox Code Playgroud)
谢谢你!乙
如果你想反转 y 轴的顺序,你可以使用scale_y_reverse()或者你可以使用scale_y_continuous(trans = "reverse")两者都会产生所需的输出
数据:
data_diff <- structure(list(Name = structure(c(4L, 10L, 9L, 1L, 7L, 11L, 8L,
5L, 13L, 6L, 3L, 2L, 12L), .Label = c("Abomasnow", "Alolan_Exeggutor",
"Appletun", "Aurorus", "Exeggutor", "Flapple", "Frosmoth", "Golem",
"Leavanny", "Parasect", "Rhyperior", "Tyranitar", "Weavile"), class = "factor"),
Sum.of.Against.Total = c(26, 25, 25, 25, 24.5, 24.25, 24.25,
24, 23.5, 23.25, 23.25, 23.25, 23), Sum.of.Diff = c(185.66,
155.66, 115.66, 115.66, 115.66, 115.66, 115.66, 115.66, 115.66,
115.66, 115.66, 82.66, 70.66)), class = "data.frame", row.names = c(NA,
-13L))
Run Code Online (Sandbox Code Playgroud)
阴谋:
library(ggplot2)
library(ggrepel)
ggplot(data=data_diff, aes(Sum.of.Diff, Sum.of.Against.Total)) +
geom_point(alpha=1) +
scale_y_reverse() +
ggtitle("Data Diff") +
geom_label_repel(data=subset(data_diff, Sum.of.Against.Total> 0 | Sum.of.Diff > 0 | Sum.of.Diff < 0), aes(label=Name), box.padding = 0.5, point.padding = .11, segment.color = 'black') +
xlab("Sum of Diff") +
ylab("Sum of Against Stats Total")
Run Code Online (Sandbox Code Playgroud)
ggplot(data=data_diff, aes(Sum.of.Diff, Sum.of.Against.Total)) +
geom_point(alpha=1) +
scale_y_continuous(trans = "reverse") +
ggtitle("Data Diff") +
geom_label_repel(data=subset(data_diff, Sum.of.Against.Total> 0 | Sum.of.Diff > 0 | Sum.of.Diff < 0), aes(label=Name), box.padding = 0.5, point.padding = .11, segment.color = 'black') +
xlab("Sum of Diff") +
ylab("Sum of Against Stats Total")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2404 次 |
| 最近记录: |