繁体   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