我正在寻找一种方法来连接我的ggplot中的各个数据点,因此请证明该数据是对同一个人随时间的重复测量。到目前为止,我已经成功创建了一个条形图,其顶部带有单独的geom_point(每个主题的数据点)。但是,我想将匹配的点连接到三个时间点之间的同一参与者。 有指针吗?
public function processDatamap_afterAllOperations(\TYPO3\CMS\Core\DataHandling\DataHandler $pObj)
{
try {
$prop = new \ReflectionProperty(
\TYPO3\CMS\Core\DataHandling\DataHandler::class,
'mmHistoryRecords'
);
$prop->setAccessible(true);
$mmHistoryRecords = $prop->getValue($pObj);
} catch (\ReflectionException $e) {
}
}
答案 0 :(得分:1)
您可以尝试
pd <- position_dodge(0.8)
ggplot(data=data_ex_long,aes(x = time, y = PANAS_score, fill = factor(group, levels = c("patient", "control")))) +
geom_bar(stat = "summary",fun.y = 'mean', color=1, position = "dodge") +
geom_point(aes(group=pnum),position = pd, shape =21) +
geom_line(aes(group=pnum),position = pd) +
geom_errorbar(stat = 'summary', position = "dodge") +
scale_fill_discrete("")
根据您的评论,我建议完全切换到stat_summary
pd <-position_dodge(.9)
data_ex_long$group <- factor(data_ex_long$group, levels = c("patient", "control"))
ggplot(data=data_ex_long,aes(x = time, y = PANAS_score, fill = group)) +
stat_summary(fun.y = "mean", geom = "bar",position = pd) +
stat_summary(aes(group = group),
fun.y = "mean", geom = "line",position = pd, size= 1.5 ) +
stat_summary(fun.data = mean_se, geom = "errorbar",position = pd, width = 0.3) +
geom_point(aes(group=pnum),position = pd, shape =21)
使用了ggplot2_3.1.0