簡體   English   中英

不需要的結果顯示ggplot boxplot

[英]Undesired result displaying ggplot boxplot

我正在繪制此數據:

Day,Property,Violent
Mon,7.2,5.7
Tue,5,4.5
Wed,6.3,3.6
Thu,5.4,4
Fri,9.5,5.6
Sat,16,10.9
Sun,14.2,8.6

使用以下代碼:

library(ggplot2)
library(reshape)
week <- read.csv("week.csv", header=TRUE)
data.melt <- melt(week,id="Day")

ggplot() +
geom_boxplot(aes(x=Day, y= value, fill= variable), 
             data= data.melt, position = position_dodge(width = .9))
  1. 為什么我的標記出現在圖例上而不出現在情節上?
  2. 如何從星期一開始邏輯上重新排序星期幾? 任何幫助將不勝感激
DF <- read.table(text="Day,Property,Violent
Mon,7.2,5.7
Tue,5,4.5
Wed,6.3,3.6
Thu,5.4,4
Fri,9.5,5.6
Sat,16,10.9
Sun,14.2,8.6", header=TRUE, sep=",")

#I would consider the weekdays ordered, so let's turn them into an ordered factor.
DF$Day <- ordered(as.character(DF$Day), as.character(DF$Day))

library(ggplot2)
library(reshape2)
data.melt <- melt(DF,id.vars="Day")

ggplot() +
  geom_boxplot(aes(x=Day, y= value, fill= variable), 
               data= data.melt, position = position_dodge(width = .9))

在此處輸入圖片說明

這樣很好。 您看不到太多,因為每個框只有一個值。 如果要實際查看顏色,則每天需要更多的值和可變的值。 另外,您可以使用geom_point

ggplot() +
  geom_point(aes(x=Day, y= value, colour= variable), 
               data= data.melt, position = position_dodge(width = .9))

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM