ggplot2 拒绝绘制数值
ggplot2 refusing to plot numerical values
我目前正在尝试为我的大学项目创建一个简单的箱线图,但似乎无法弄清楚我做错了什么。
我目前的代码如下:
ggplot(wait_c_long, aes(x='Period', y='Days waited at the 50th percentile')) + geom_point()
wait_c_long = My dataframe
Period = Ordered factor class variable of time periods e.g. '2014-15'...'2018-19'.
第 50 个百分位的等待天数 = 平均等待时间的数值 class 变量。
这是我的数据集的截图以供参考:
每当我 运行 前面所述的命令时,它都会产生以下输出 只有一个数据点,并告诉我 y 轴上的变量是离散的,尽管它是数字 .
理想情况下,我想使用 geom_point 函数创建一个简单的散点图,使用以下 aes(x='Period',y='Days waited at the 50th percentile', color = 'State', size = 'Admissions')
从我的数据集创建一个数据可视化,我可以在我的作业中使用,所以任何帮助都会不胜感激。
通常在 aes()
中,您不会引用数据框列的名称,但是当它们有空格时,这不起作用,因此您需要使用左单引号进行引用。您最终得到代码:
library(ggplot2)
#Create an example dataset in the same format
wait_c_long <- data.frame(Period=1:5, Days=1:5)
names(wait_c_long)[2] <- 'Days waited at the 50th percentile'
#Use no quotes/forward quotes to reference the columns
ggplot(wait_c_long, aes(x=Period, y=`Days waited at the 50th percentile`)) + geom_point()
尝试使用反引号代替撇号作为变量。
ggplot(wait_c_long, aes(x=`Period`, y=`Days waited at the 50th percentile`)) +
geom_point()
wait_c_long = My dataframe
Period = Ordered factor class variable of time periods e.g. '2014-15'...'2018-19'.
我目前正在尝试为我的大学项目创建一个简单的箱线图,但似乎无法弄清楚我做错了什么。
我目前的代码如下:
ggplot(wait_c_long, aes(x='Period', y='Days waited at the 50th percentile')) + geom_point()
wait_c_long = My dataframe
Period = Ordered factor class variable of time periods e.g. '2014-15'...'2018-19'.
第 50 个百分位的等待天数 = 平均等待时间的数值 class 变量。
这是我的数据集的截图以供参考:
理想情况下,我想使用 geom_point 函数创建一个简单的散点图,使用以下 aes(x='Period',y='Days waited at the 50th percentile', color = 'State', size = 'Admissions')
从我的数据集创建一个数据可视化,我可以在我的作业中使用,所以任何帮助都会不胜感激。
通常在 aes()
中,您不会引用数据框列的名称,但是当它们有空格时,这不起作用,因此您需要使用左单引号进行引用。您最终得到代码:
library(ggplot2)
#Create an example dataset in the same format
wait_c_long <- data.frame(Period=1:5, Days=1:5)
names(wait_c_long)[2] <- 'Days waited at the 50th percentile'
#Use no quotes/forward quotes to reference the columns
ggplot(wait_c_long, aes(x=Period, y=`Days waited at the 50th percentile`)) + geom_point()
尝试使用反引号代替撇号作为变量。
ggplot(wait_c_long, aes(x=`Period`, y=`Days waited at the 50th percentile`)) +
geom_point()
wait_c_long = My dataframe
Period = Ordered factor class variable of time periods e.g. '2014-15'...'2018-19'.