R 为点图添加棒棒糖棒
如何(如果可能的话)将棒棒糖棒添加到点图中 比如说,R 为点图添加棒棒糖棒,r,ggplot2,R,Ggplot2,如何(如果可能的话)将棒棒糖棒添加到点图中 比如说, plot(1:10, sin(1:10)) 如何从十个点中的每一个点向x轴添加一条垂直线(棒棒糖棒)?我需要编写一个函数来绘制每个木棍吗?segments函数将执行您想要的操作 plot(1:10, sin(1:10)) abline(h=0, lty=2) segments(1:10, 0, 1:10, sin(1:10)) 分段功能将执行您想要的操作 plot(1:10, sin(1:10)) abline(h=0, lty=2) s
plot(1:10, sin(1:10))
如何从十个点中的每一个点向x轴添加一条垂直线(棒棒糖棒)?我需要编写一个函数来绘制每个木棍吗?segments函数将执行您想要的操作
plot(1:10, sin(1:10))
abline(h=0, lty=2)
segments(1:10, 0, 1:10, sin(1:10))
分段功能将执行您想要的操作
plot(1:10, sin(1:10))
abline(h=0, lty=2)
segments(1:10, 0, 1:10, sin(1:10))
您有一个
ggplot2
标记,但使用一个基本示例,因此我将同时显示这两个标记
数据:
ggplot2
允许您在geom_段中指定起点和终点
ggplot(df, aes(x, y)) +
geom_point() +
geom_segment(aes(x = x, y = 0, xend = x, yend = y)) +
geom_hline(yintercept = 0, lty = 2)
您有一个
ggplot2
标记,但使用一个基本示例,因此我将同时显示这两个标记
数据:
ggplot2
允许您在geom_段中指定起点和终点
ggplot(df, aes(x, y)) +
geom_point() +
geom_segment(aes(x = x, y = 0, xend = x, yend = y)) +
geom_hline(yintercept = 0, lty = 2)
因为我们不想使用
ggalt::geom_lollipop()
:
devtools::install_github(“hrbrmstr/ggalt”)
df因为我们不想使用ggalt::geom_lollipop()
:
devtools::install_github(“hrbrmstr/ggalt”)
df是否也适用于我用作示例的函数?它似乎只适用于系数geom\uuz
使用了与您所用的ggplot2答案相同的基本原理。它是否也适用于我作为示例使用的函数?似乎它只适用于系数geom_uuu
使用了与您标记为正确的ggplot2答案相同的基本原理。另一个plot(1:10,sin(1:10),type='h');点(1:10,sin(1:10))
另一个绘图(1:10,sin(1:10),类型='h');点数(1:10,sin(1:10))
devtools::install_github("hrbrmstr/ggalt")
df <- read.csv(text="category,pct
Other,0.09
South Asian/South Asian Americans,0.12
Interngenerational/Generational,0.21
S Asian/Asian Americans,0.25
Muslim Observance,0.29
Africa/Pan Africa/African Americans,0.34
Gender Equity,0.34
Disability Advocacy,0.49
European/European Americans,0.52
Veteran,0.54
Pacific Islander/Pacific Islander Americans,0.59
Non-Traditional Students,0.61
Religious Equity,0.64
Caribbean/Caribbean Americans,0.67
Latino/Latina,0.69
Middle Eastern Heritages and Traditions,0.73
Trans-racial Adoptee/Parent,0.76
LBGTQ/Ally,0.79
Mixed Race,0.80
Jewish Heritage/Observance,0.85
International Students,0.87", stringsAsFactors=FALSE, sep=",", header=TRUE)
library(ggplot2)
library(ggalt)
library(scales)
gg <- ggplot(df, aes(y=reorder(category, pct), x=pct))
gg <- gg + geom_lollipop(point.colour="steelblue", point.size=3, horizontal=TRUE)
gg <- gg + scale_x_continuous(expand=c(0,0), labels=percent,
breaks=seq(0, 1, by=0.2), limits=c(0, 1))
gg <- gg + labs(x=NULL, y=NULL,
title="SUNY Cortland Multicultural Alumni survey results",
subtitle="Ranked by race, ethnicity, home land and orientation\namong the top areas of concern",
caption="Data from http://stephanieevergreen.com/lollipop/")
gg <- gg + theme_minimal(base_family="Arial Narrow")
gg <- gg + theme(panel.grid.major.y=element_blank())
gg <- gg + theme(panel.grid.minor=element_blank())
gg <- gg + theme(axis.line.y=element_line(color="#2b2b2b", size=0.15))
gg <- gg + theme(axis.text.y=element_text(margin=margin(r=-5, l=0)))
gg <- gg + theme(plot.margin=unit(rep(30, 4), "pt"))
gg <- gg + theme(plot.title=element_text(face="bold"))
gg <- gg + theme(plot.subtitle=element_text(margin=margin(b=10)))
gg <- gg + theme(plot.caption=element_text(size=8, margin=margin(t=10)))
gg