回复 第4楼 的 ricklovelisa:factor对ordinal data还是比字符串有好些的。
factor是为Likert-scale/ordinal data而生的。
回复 第4楼 的 ricklovelisa:factor对ordinal data还是比字符串有好些的。
factor是为Likert-scale/ordinal data而生的。
回复 第4楼 的 yanlinlin82:
请问能说说用ODBC的弊端吗?
回复 第3楼 的 wyfhdl:
请问你在其他的SQL editor中看过query的结果吗?如果editor中的结果没问题,就说明是R处理的问题。
建议你使用sqlQuery(stringsAsFactors = FALSE),然后自己处理接受到的数据。
在生成data frame时,R将所有的character value视为nominal data,然后转换为factor类型(如果不设定stringsAsFactors = FALSE),所以factor的结果总不尽如人意。
不能重现你说的错误。
你试试先rm(mtcars),再重新运行一遍code。
回复 第8楼 的 YSU:Good catch, thanks!
问题的难点在于每个facet中x axis的order都不相同,所以基本排除可以用一个scale_x_*()或者说一个图实现的可能。
作为替代,你可以分别绘制三个ggplots p1, p2, p3 后,通过grid.arrange( p1, p2, p3 )显示。
library(gridExtra)
tmp <- subset(data, items == "earprotector", c(names, quantity))
tmp$names <- factor(tmp$names, levels = tmp[order(tmp$quantity), "names"])
p1 <- ggplot(tmp, aes(x = names, y = quantity)) +
geom_bar(stat = 'identity')
tmp <- subset(data, items == "footprotector", c(names, quantity))
tmp$names <- factor(tmp$names, levels = tmp[order(tmp$quantity), "names"])
p2 <- ggplot(tmp, aes(x = names, y = quantity)) +
geom_bar(stat = 'identity')
tmp <- subset(data, items == "gloves", c(names, quantity))
tmp$names <- factor(tmp$names, levels = tmp[order(tmp$quantity), "names"])
p3 <- ggplot(tmp, aes(x = names, y = quantity)) +
geom_bar(stat = 'identity')
grid.arrange( p1, p2, p3 )
不是大神。仅从你给出的代码判断,我认为最有可能是query的结果中没有ChangeDate为8月19号以后的数据。