Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在R ggplot2中按n缩放x/y连续中断?_R_Ggplot2 - Fatal编程技术网

在R ggplot2中按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) {

我有一些图,我想用不同的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) { 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))