我對應用于我的資料的 dotplot 函式有一些麻煩。我可以使用鉆石資料重現這個問題。問題是一些不同的值被組合在一起,而它們不應該組合在一起。例如,兩個黃點(“J”)對齊在一起,一個是 64,另一個是 63.8。還有另一個值 63.8 顏色為“E”,就在下面。根據價值,我想要更準確的東西。似乎值是四舍五入的,有時這些值在幾行上分開。我沒有看到其他資料的問題(參見示例 2)。
示例 1
data("diamonds")
dia=diamonds[1:30,]
dia[order(dia$depth, decreasing = TRUE), ]
carat cut color clarity depth table price x y z
9 0.22 Fair E VS2 65.1 61 337 3.87 3.78 2.49
11 0.30 Good J SI1 64.0 55 339 4.25 4.28 2.73
19 0.30 Good J SI1 63.8 56 351 4.23 4.26 2.71
22 0.23 Very Good E VS2 63.8 55 352 3.85 3.92 2.48
18 0.30 Good J SI1 63.4 54 351 4.23 4.29 2.70
5 0.31 Good J SI2 63.3 58 335 4.34 4.35 2.75
21 0.30 Good I SI2 63.3 56 351 4.26 4.30 2.71
6 0.24 Very Good J VVS2 62.8 57 336 3.94 3.96 2.48
12 0.23 Ideal J VS1 62.8 56 340 3.93 3.90 2.46
20 0.30 Very Good J SI1 62.7 59 351 4.21 4.27 2.66
27 0.24 Premium I VS1 62.5 57 355 3.97 3.94 2.47
4 0.29 Premium I VS2 62.4 58 334 4.20 4.23 2.63
7 0.24 Very Good I VVS1 62.3 57 336 3.95 3.98 2.47
14 0.31 Ideal J SI2 62.2 54 344 4.35 4.37 2.71
28 0.30 Very Good J VS2 62.2 57 357 4.28 4.30 2.67
17 0.30 Ideal I SI2 62.0 54 348 4.31 4.34 2.68
8 0.26 Very Good H SI1 61.9 55 337 4.07 4.11 2.53
1 0.23 Ideal E SI2 61.5 55 326 3.95 3.98 2.43
23 0.23 Very Good H VS1 61.0 57 353 3.94 3.96 2.41
16 0.32 Premium E I1 60.9 58 345 4.38 4.42 2.68
30 0.23 Very Good F VS1 60.9 57 357 3.96 3.99 2.42
29 0.23 Very Good D VS2 60.5 61 357 3.96 3.97 2.40
13 0.22 Premium F SI1 60.4 61 342 3.88 3.84 2.33
26 0.23 Very Good G VVS2 60.4 58 354 3.97 4.01 2.41
15 0.20 Premium E SI2 60.2 62 345 3.79 3.75 2.27
2 0.21 Premium E SI1 59.8 61 326 3.89 3.84 2.31
10 0.23 Very Good H VS1 59.4 61 338 4.00 4.05 2.39
24 0.31 Very Good J SI1 59.4 62 353 4.39 4.43 2.62
25 0.31 Very Good J SI1 58.1 62 353 4.44 4.47 2.59
3 0.23 Good E VS1 56.9 65 327 4.05 4.07 2.31
>
ggplot(dia, aes(y=depth, x=""))
geom_boxplot()
geom_dotplot(aes(fill=factor(color)), binaxis='y', stackdir='center', dotsize=0.5, stackgroups = TRUE)

使用我創建的其他資料(見下文)以更好地了解正在發生的事情,問題不再存在
示例 2
abb=c(1,1.5,1.5,1.5,2,2,2,2.5,3.5,5,5,5.5,5.5)
bcc=c("Lyon", "Lyon", "Bordeaux", "Bordeaux", "Chambéry", "Lyon", "Lyon", "Nantes", "Nantes", "Lyon", "Lyon", "Rennes", "Lyon")
Fil=data.frame(abb,bcc)
> Fil
abb bcc
1 1.0 Lyon
2 1.5 Lyon
3 1.5 Bordeaux
4 1.5 Bordeaux
5 2.0 Chambéry
6 2.0 Lyon
7 2.0 Lyon
8 2.5 Nantes
9 3.5 Nantes
10 5.0 Lyon
11 5.0 Lyon
12 5.5 Rennes
13 5.5 Lyon
with dotplot, I the value 5 and 5.5 are group together. I would like the same but with different "lines" for this values
ggplot(Fil, aes(y=abb, x=""))
geom_boxplot()
geom_dotplot(aes(fill=factor(bcc)), binaxis='y', stackdir='center', dotsize=0.5, stackgroups = TRUE)
scale_fill_manual(values = c("#FF8000", "#FF0033","#80FF00","#FFFF00", "#000000"))

What are the solution to fix this problem ?
uj5u.com熱心網友回復:
您只需要更改binwidth. 在我更改之前,我binwidth從 ggplot 收到一條關于選擇binwidth. 我收到的訊息說
bin 寬度默認為資料范圍的 1/30。選擇更好的價值
binwidth。
ggplot2告訴你這binwidth是問題所在
ggplot(dia, aes(y=depth, x=""))
geom_boxplot()
geom_dotplot(aes(fill=factor(color)), binaxis='y', stackdir='center', dotsize=0.5, stackgroups = TRUE,binwidth = 0.2)

固定垃圾箱寬度只是一個創可貼。我認為使用geom_jitter可能是一個不錯的選擇
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/371944.html
