我是R脚本的新手,不要对我太苛刻:)。
所以我有一个CSV文件,看起来像这样:
Day |Date |Temperature |Pression |Flow
----|-----------|---------------|-----------|------
1 |5/10/2017 |85 |4 |100
2 |5/11/2017 |85 |4.5 |102
3 |5/12/2017 |88 |5.2 |103
4 |5/13/2017 |83 |4.1 |99
.. |..... |.. |... |..我执行了导入CSV数据的必要步骤。
我使用qcc函数对Xbar进行质量控制。
我得到了我的图形,但是坐标X和Y是颠倒的。Xbargrap
我希望在X坐标中,日期的值具有正确的格式(不是17300,而是5-10-2017),并且在Y坐标中具有压力。
我试了几次,但是我做不到:/
这是我的程序:
# Library
library(qcc)
library(readr)
library(Rserve)
Rserve(args = "--vanilla")
# Data column filter from CSV file imported
Test <- read_csv("C:/Users/..../Desktop/Test.csv",
col_types = cols(Date = col_date(format = "%m/%d/%Y")))
diams <- qcc.groups(Test$Date,Test$Pression)
#diams <- with(Test, qcc.groups(Day, Temperature))
#Background color
qcc.options(bg.margin = "white", bg.figure = "gray95")
#Xbar graph (means of a continuous process variable)
qcc(
data = diams,
type = "xbar",
sizes = 5,
title = "Sample X-bar Chart Title", # Replacement title
digits = 2, # Limit the signifciant figures
plot = TRUE)你能帮我吗?
感谢您的回答。
发布于 2017-06-15 15:10:14
我想说的是:试着学习使用data.table和ggplot2包。如果你使用这些..然后,绘制日期也变得更加容易。
你可以试试这段代码
library(data.table)
library(ggplot2)
# Use fread (fast-read) to get the csv
table = fread("C:/Users/..../Desktop/Test.csv")
# convert to date
table[,Date := as.Date(Date,format = "%m/%d/%Y)]
#use ggplot to plot the a line
# aes stands for aesthetics
ggplot(data = table,aes(x = Date,y = Pression)) + geom_line()
# If you want to keep your lines.. you can add them with geom_vline()发布于 2017-06-28 09:56:52
使用ggQC软件包可以实现带有控制图线条的ggplot
这里有两个例子,其中模拟了你的数据集(外加分面奖励)
每天一次观察
#Simulate some data
df <- data.frame(
"index" = 1:48,
"date" = seq.Date(from = as.Date("2017-5-10"),
to = as.Date("2017-6-26" ),
by="1 day"),
"pression" = rnorm(n=48, mean = 4.7, sd = .2)
)
require(ggQC)
require(ggplot2)
ggplot(df, aes(x=date, y=pression)) +
stat_QC(method = "XmR") + #draw the QC lines
stat_QC_labels(method = "XmR") + # label the QC lines
geom_point() + geom_line() # draw points and lines每天的5观察量
#Make some data with group size = 5
df2 <- data.frame(
"index" = 1:48*5,
"date" = rep(
seq.Date(from = as.Date("2017-5-10"),
to = as.Date("2017-6-26" ),
by="1 day"),
each = 5
),
"pression" = rnorm(n=48*5, mean = 4.7, sd = .2)
)
require(ggQC)
require(ggplot2)
ggplot(df2, aes(x=date, y=pression)) +
geom_point(alpha=.3) + # show the individuals
stat_summary(fun.y = mean, geom="point", color="black") + #show mean by day
stat_summary(fun.y = mean, geom="line", color="red") + #draw a line
stat_QC() + # draw the qc lines
stat_QC_labels() # write the labels on the lines因为它的聚集图,你还可以做一些很酷的事情,比如按月分面(例如)
df2$month <- cut(df2$date, breaks = "1 month")
ggplot(df2, aes(x=date, y=pression)) +
geom_point(alpha=.3) + # show the individuals
stat_summary(fun.y = mean, geom="point", color="black") + #show mean by day
stat_summary(fun.y = mean, geom="line", color="red") + #draw a line
stat_QC() + # draw the qc lines
stat_QC_labels() + # write the labels on the lines
facet_grid(.~month, scales = "free_x")发布于 2017-06-29 17:07:56
您应该能够获得以下图表

从下面的代码:
set.seed(5557)
df3 <- data.frame(
"index" = 1:48,
"date" = seq.Date(from = as.Date("2017-5-10"),
to = as.Date("2017-6-26" ), by="1 day"),
"Temperature" = rnorm(n=48, mean=83, sd=5)
)
require(ggQC)
require(ggplot2)
ggplot(df3, aes(x=date, y=Temperature)) +
stat_QC(method = "XmR") + #draw the QC lines
stat_QC_labels(method = "XmR") + # label the QC lines
geom_point() + geom_line() # draw points and lineshttps://stackoverflow.com/questions/44559659
复制相似问题