[英]Unexpected theme change in ggplot2
我在ggplot2的外觀中得到了意外的行為。 當我繪制大量數據時,似乎默認主題從theme_grey更改為theme_bw。 我可以在正在處理的特定數據集上重現它,但不能在模擬數據上重現它。
無論如何,這是代碼:
ggplot(df2, aes(x = Sequence, y = y, color = as.factor(group))) +
geom_point(shape=19, alpha = 0.8)
nrow(df2)
[1] 4330
現在,如果我獲取數據的子集:
df3 <- slice(df2, 1:10)
ggplot(df3, aes(x = Sequence, y = y, color = as.factor(group))) +
geom_point(shape=19, alpha = 0.8)
我努力了:
5個樣本的樣本:
> dput(df2[1:5, ])
structure(list(Sequence = c("1", "2", "3", "4", "5"), group = c(0,
0, 0, 0, 0), y = c(7711.945, 7695.075, 3432.585, 8081.19, 7344.455
)), .Names = c("Sequence", "group", "y"), row.names = c(NA, 5L
), class = "data.frame")
您輸入的“ x”當前存儲為一個因子(我猜是這樣)。 以下代碼將重現您遇到的問題,並將x轉換為數字的最后一行解決了該問題。
# make some test input
n <- 5000
df <- data.frame(x = factor(1:n), y = rnorm(n), group = sample(0:1, n, replace = T))
library(ggplot2)
# Using the x "as is" which is currently a factor
ggplot(df, aes(x = x, y =y, color = as.factor(group))) + geom_point(shape = 19, alpha = 0.8)
# Converting to numeric we see the desired result
ggplot(df, aes(x = as.numeric(x), y =y, color = as.factor(group))) + geom_point(shape = 19, alpha = 0.8)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.