在R ggplot2中按n缩放x/y连续中断?
我有一些图,我想用不同的n来打断x或/和y轴。 为了实现这一点,我有十几个功能,如:在R ggplot2中按n缩放x/y连续中断?,r,ggplot2,R,Ggplot2,我有一些图,我想用不同的n来打断x或/和y轴。 为了实现这一点,我有十几个功能,如: by_two <- function(x) { seq(0, max(x), by = 2) } by_two我不知道如何将序列限制在给定数据的范围内,但我不确定这是否必要,因为ggplot只使用数据的范围 # Hacky, but ggplot ignores breaks beyond what's needed for the data by_n <- function(n) {
by_two <- function(x) {
seq(0, max(x), by = 2)
}
by_two我不知道如何将序列限制在给定数据的范围内,但我不确定这是否必要,因为ggplot只使用数据的范围
# Hacky, but ggplot ignores breaks beyond what's needed for the data
by_n <- function(n) { seq(0, 1000, by = n) }
ggplot(iris,
aes(x = Sepal.Length,
fill = Species)) +
geom_density(alpha = .3) +
labs(title = paste0("Without Normalization Analysis [K = 2]")) +
scale_fill_discrete(name = "Users") +
scale_x_continuous(breaks = by_n(0.5))
#有点老套,但ggplot忽略了数据所需之外的中断
顺便说一下,我不知道如何将序列限制在给定数据的范围内,但我不确定这是否必要,因为ggplot只使用数据的范围
# Hacky, but ggplot ignores breaks beyond what's needed for the data
by_n <- function(n) { seq(0, 1000, by = n) }
ggplot(iris,
aes(x = Sepal.Length,
fill = Species)) +
geom_density(alpha = .3) +
labs(title = paste0("Without Normalization Analysis [K = 2]")) +
scale_fill_discrete(name = "Users") +
scale_x_continuous(breaks = by_n(0.5))
#有点老套,但ggplot忽略了数据所需之外的中断
顺便说一句,请使用dput()
(不是str
或head
或图片/屏幕截图)共享您的数据样本,以便其他人可以提供帮助。请使用dput()
(不是str
或head
或图片/屏幕截图)共享您的数据样本,以便其他人可以提供帮助。在这里看到更多
p1 <- ggplot(users_d_total %>% filter(isSame, D_rank == 2), aes(x = D, fill = as.factor(train_user_id))) +
geom_density(alpha = .3) +
labs(title = paste0("Without Normalization Analysis [K = 2]")) +
scale_fill_discrete(name = "Users") +
scale_x_continuous(breaks = by_n(1))
# Hacky, but ggplot ignores breaks beyond what's needed for the data
by_n <- function(n) { seq(0, 1000, by = n) }
ggplot(iris,
aes(x = Sepal.Length,
fill = Species)) +
geom_density(alpha = .3) +
labs(title = paste0("Without Normalization Analysis [K = 2]")) +
scale_fill_discrete(name = "Users") +
scale_x_continuous(breaks = by_n(0.5))