我有以下数据框:
person step start end
1 sam A 0 4
2 sam B 4 6
3 greg A 2 7
4 greg B 7 11
我创建了下面的图:
library(ggplot2)
library(dplyr)
library(tidyr)
df
ggplot(df, aes(colour=step)) +
geom_segment(aes(x=start, xend=end, y=person, yend=person), size=3) +
xla
"+"算子在ggplot2中和"%>%"算子在magrittr中有什么区别?
我被告知,它们是相同的,但是,如果我们考虑以下脚本。
library(magrittr)
library(ggplot2)
# 1. This works
ggplot(data = mtcars, aes(x=wt, y = mpg)) + geom_point()
# 2. This works
ggplot(data = mtcars) + aes(x=wt, y = mpg) + geom_point()
# 3. This works
ggplot(data =
我试图用它的数据作为填充来绘制一个shapefile。在尝试此操作时,我不幸地遇到了错误Aesthetics must be either length 1 or the same as the data (8112701): fill。
我的数据是一个284个长的SpatialPolygonsDataFrame,格式是
nations
@data
$OBJECTID (numeric)
$CNTRY_NAME (chr)
$CNTRY_CODE (chr)
$BPL_CODE (chr)
$deaths (numeric)
$cases (
使用ggplot2,我尝试在极线图中绘制两个处理。我可以绘制两个治疗的点图,并为我输入的第一个治疗得到一条线,但我想要连接第二个子集的线正好覆盖在第二个子集上。
category highest lowest
1 A 71 23
2 B 81 38
3 C 77 22
4 D 83 56
5 E 84 32
6 F 82 55
7 G 73
我有以下几点:
require(ggplot2)
p <- ggplot() # don't put aes() here, do it separately
df <- data.frame(x=X, y=Y) # ggplot requires dataframes
p <- p + geom_line(data=df, aes(x=X, y=Y))
# Now we plot the graphs using ggplots and color the segments
p <- p + geom_rect(data=peaks,
The article discussing tidy evaluation in ggplot2给人的印象是aes()现在支持准报价。但是,我在使用无引号拼接操作符!!!时遇到了问题。 library( ggplot2 )
## Predefine the mapping of symbols to aesthetics
v <- rlang::exprs( x=wt, y=mpg )
## Symbol-by-symbol unquoting works without problems
ggplot( mtcars, aes(!!v$x, !!v$y) ) + geom_po