我不知道为什么但R不允许我在我的情节上添加一条线和点(即pch
,lty
和lwt
不起作用)< / p>
x轴值是因子。 我只想创建一个包含观察值的行。
为什么会这样?
这是我的代码:
> df
Var1 Freq
1 Oct 234
2 Nov 100
3 Dec 1653
4 Jan 800
5 Feb 960
6 Mar 1182
7 Apr 389
8 May 1333
9 Jun 2251
10 Jul 2221
11 Aug 1012
12 Sep 362
x1 = factor(df$Var1, levels = c('Oct', 'Nov', 'Dec', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep'))
df$Freq = as.numeric(as.character(df$Freq))
plot(x1, df$Freq, type = 'b')
答案 0 :(得分:1)
这就是你要追求的吗?
ssn_regexp = /\A\d{2}\.\d{2}\.\d{2}-\d{3}\.\d{2}\z/
validates :ssn,
format: { with: ssn_regexp }
# The sample data
df <- cbind.data.frame(
Var1 = c("Oct","Nov","Dec","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep"),
Freq = c(1101, 1158, 1753, 1918, 1296, 682, 389, 333, 251, 221, 312, 362));
x1 = factor(df$Var1, levels = c('Oct', 'Nov', 'Dec', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep'))
# This has no purpose as df$Freq is already numeric
df$Freq = as.numeric(as.character(df$Freq))
# Turn x1 factors into numeric values and
# plot as line plot without x-axis labels
plot(as.numeric(x1), df$Freq, type = 'l',
xaxt = "n",
xlab = "Month",
ylab = "Freq");
# Add custom x-axis with labels
# given by the levels of x1
axis(1, at = as.numeric(x1), labels = as.character(x1));