连接ggplot2的x值内的点?

Connect points within x values for ggplot2?


连接ggplot2的x值内的点? 已获得1个解决方法 2020-08-18 18:08:46 r

我正在绘制一系列由两个因素分组的点.我想在一组中的另一组中以及在x值 (跨位置-道奇距离) 内添加线,以直观地突出显示数据中的趋势.

geom_line(),geom_segment() 和geom_path() 似乎都仅绘制到实际的x值,而不是数据点的位置躲避位置.有没有办法在x值内添加一条连接点的线?

这是一个结构上类似的示例:

# Create a sample data set
d <- data.frame(expand.grid(x=letters[1:3], 
                g1=factor(1:2), 
                g2=factor(1:2)),      
                y=rnorm(12))

# Load ggplot2
library(ggplot2)

# Define position dodge
pd <- position_dodge(0.75)

# Define the plot
p <- ggplot(d, aes(x=x, y=y, colour=g1, group=interaction(g1,g2))) +
     geom_point(aes(shape = factor(g2)), position=pd) +
     geom_line()

# Look at the figure
p

# How to plot the line instead across g1, within g2, and within x?

连接ggplot2的x值内的点? 方法1

只是试图关闭这个问题 (@ Axeman请随时接管我的答案).

p <- ggplot(d, aes(x=x, y=y, colour=g1, group=interaction(g1,g2))) +
     geom_point(aes(shape = factor(g2)), position=pd) +
     geom_line(position = pd)

# Look at the figure
p


.htaccess .net .net-core 2d 3d 3d-printing ab-initio abp abstract-syntax-tree actions-on-google actionscript-3 active-directory activemq activemq-artemis acumatica adobe-xd aframe ag-grid agora.io air airflow ajax akka alert alexa algorithm alignment allure amadeus amazon-cloudformation