我有一个与拍号 (0-100) 相对应的角度数据 (0-360) 数据集,并使用 ggplot 创建散点图。
ggplot(kfaf)+
geom_point(aes(time, angle, color = condition), size = 1.5)
Run Code Online (Sandbox Code Playgroud)

我想做的是格式化 y 轴,使 0=360 并从 ymin = 270 读取到 ymax = 269,功能上移动图表,使 0/360 位于 y 轴的中间。找不到任何用于格式化圆形数据轴的内容,有帮助吗?
如果我理解正确,OP 想要绘制数据,以便 y 轴覆盖从 -270 到 +270 度的范围。
这可以通过将数据加倍并移动angle值来实现:
# create dummy data
DF <- data.frame(angle = seq(0, 350, 10),
time = 1:36)
# doubling the data
library(dplyr)
DF2 <- DF %>%
mutate(angle = angle - 360) %>%
bind_rows(DF)
library(ggplot2)
ggplot(DF2) +
aes(time, angle) +
geom_point() +
scale_y_continuous(breaks = seq(-360, 360, 60), limits = c(-270, 269)) +
theme_bw()
Run Code Online (Sandbox Code Playgroud)
OP 已澄清他不希望 y 轴上出现负值。这可以通过在调用中设置标签和中断来完成scale_y_continuous():
brks <- seq(-360, 360, 30)
lbls <- brks %% 360 %>%
as.character() %>%
replace(. == "0", "0/360")
library(ggplot2)
ggplot(DF2) +
aes(time, angle) +
geom_point() +
scale_y_continuous(breaks = brks, labels = lbls, limits = c(-90, 269)) +
theme_bw()
Run Code Online (Sandbox Code Playgroud)
限制范围已设置为 -90 到 269 度,根据要求打印为 270 到 269。
我特意选择将标签修改为 0 度,"0/360"以指示圆形字符(并与下面的极坐标图一致)。
DF另一种可能性是在极坐标中绘制原始数据集:
ggplot(DF) +
aes(angle, time) +
geom_point() +
coord_polar() +
scale_x_continuous(breaks = seq(0, 360, 60), limits = c(0, 360)) +
theme_bw()
Run Code Online (Sandbox Code Playgroud)
请注意,中的参数aes()已交换。x 轴代表角度。