我有这个代码:
ggplot() +
stat_smooth(data=fd.area.dfa.quant,aes(x=area,y=q50),alpha=0.6,colour="Red")+
stat_smooth(data=fd.area.dfb.quant,aes(x=area,y=q50),alpha=0.6,colour="Green")+
stat_smooth(data=fd.area.cfa.quant,aes(x=area,y=q50),alpha=0.6,colour="Purple")+
stat_smooth(data=fd.area.csb.quant,aes(x=area,y=q50),alpha=0.6,colour="Blue")+
stat_smooth(data=fd.area.bsk.quant,aes(x=area,y=q50),alpha=0.6,colour="Orange")+
scale_x_log10("xlab",expand = c(0, 0),labels=comma)+
scale_y_log10("ylab", expand = c(0, 0.05),labels=comma)+
theme(aspect.ratio=1)+
ggtitle("title")+
ggsave("save2.png")
Run Code Online (Sandbox Code Playgroud)
这就是数字
我想要
PS所有线都有各种尺寸,因此我避免融化.
我该怎么做?
我有1000个时间序列向量,并希望在ggplot2图上绘制所有这些向量,x轴的范围为(1:1000).我还想将alpha设置得相对较低,以查看某些区域的密度.
有没有办法在没有1000 geom_line语句的情况下执行此操作?
我有一个列表,其中包含各种长度的多个向量(总共80个).在x轴上我想要这些矢量的名称.在y轴上,我想绘制对应于每个向量的值.我怎么能在R?
我有这个ggplot2脚本:
require(reshape2)
library(ggplot2)
library(RColorBrewer)
library(extrafont)
font_import(pattern = 'Arch')
font_import(pattern = 'Akk')
fileName = paste("/ex_spectra.csv", sep = "") # data: https://www.dropbox.com/s/gs1hwv3xjnlhb7z/ex_spectra.csv?dl=0
mydata = read.csv(fileName,sep=",", header=TRUE, check.names=FALSE)
dataM = melt(mydata,c("x"))
my_palette = c(brewer.pal(5, "Set1")[c(1,2,3,4,5)])
ggplot(data=dataM, aes(x= x, y=value, colour=variable, fill = variable, size = variable)) +
geom_line(alpha = .75) +
scale_colour_manual(breaks=c("A", "B", "C", "D", "E"), values=my_palette) +
scale_size_manual(breaks=c("A", "B", "C", "D", "E"), values=c(0.7,0.7,0.7,0.7,0.7)) +
theme(plot.background = element_blank(), panel.grid.minor = element_blank(), #panel.grid.major = element_blank(),
axis.line = element_blank(),
legend.key = element_blank(), legend.title …Run Code Online (Sandbox Code Playgroud) 在常规R图中,我可以通过改变cex参数来使点更小或更大.如果我使用ggplot,我该怎么做呢?特别是,我正在制作ggplot并希望缩小点数.谢谢!
感谢那些评论的人.但我不知道如何使用sizeqqplot.我的代码如下.
qplot(sample=Shape, data=shape.mop, colour=Type) +
theme(legend.position="bottom") +
geom_point(size=0.5)
Run Code Online (Sandbox Code Playgroud) data <- dput(data): structure(list(x = 1:16, y = c(-79.62962963, -84.72222222, -88.42592593, -74.07407407, -29.62962963, 51.38888889, 79.62962963, 96.2962963, 87.96296296, 88.42592593, 73.14814815, 12.96296296, -63.42592593, -87.03703704, -87.5, -87.96296296)), .Names = c("x", "y"), row.names = c(NA, 16L), class = "data.frame")
Run Code Online (Sandbox Code Playgroud)
我在R中用ggplot2计算了我的数据集的平滑线:
p1 <- ggplot(data, aes(x=x(°), y=(%)))
library(splines)
library(MASS)
(p2 <- p1 + stat_smooth(method = "lm", formula = y ~ ns(x,3)) +
geom_point()
)
Run Code Online (Sandbox Code Playgroud)
如何计算平滑线曲线最大值的x值?
我想在ggplot中创建一个散点图,其中每个x值都有多个y值.我想添加这些y值并将总和与x值进行绘制.
>df
a b
1 2
1 2
2 1
2 4
3 1
3 5
Run Code Online (Sandbox Code Playgroud)
我想要一个绘制每个a的b值之和的图
a b
1 4
2 5
3 6
Run Code Online (Sandbox Code Playgroud)
我可以通过制作堆积的条形图来为条形图做到这一点:
ggplot(data=df, aes(x=df$a, y=df$b)) + geom_bar(stat="identity")
但是,如果我使用geom_point ggplot执行此操作,只需绘制y的每个值而不进行堆叠.
我可以使用ddply,但这需要更多的步骤.如果有更方便的方式,我会很感激.
我在网站上搜索了其他答案.虽然有很多关于"堆积散点图"的信息,但它们都是关于叠加的图.
这不应该是这么难,但我被困住了.我有一个以下表格的表格:
| 1 | 2 | 3
------------------------------------
TypeA | 3213 | 2121 | 43
TypeB | 31321 | 321 | 10
TypeC | 332 | 11 | 9
Run Code Online (Sandbox Code Playgroud)
我想生成一条线图,有三条线:每条Type一条,x坐标为"1,2,3",y坐标为数字(3213,...).我按照这里的步骤操作,但不知道如何迭代第一列.
geom_rectggplot2 存在问题.我想用浅蓝色遮挡vline左边的区域.但是,这很有趣.(也许是因为涉及的日期栏).
代码:
library(dplyr)
library(ggplot2)
library(scales)
df <- read.csv("~/Desktop/dataset.csv")
# df <- df[!duplicated(df$caseid),]
df$createdat <- as.numeric(as.character(df$createdat))
df$resolutionat <- as.numeric(as.character(df$resolutionat))
df <- df[df$resolutionat != 0,]
df <- mutate(df, age = (resolutionat - createdat))
df <- mutate(df, counts = assigneechangecount + teamchangecount)
df <- mutate(df, isbreached = rbinom(388, 1, 0.2))
df<- mutate(df, resolutiondate = as.POSIXct(df$resolutionat, origin="1970-01-01"))
xstart <- as.POSIXct("2016-04-26 20:36:21 IST")
xend <- as.POSIXct("2016-04-28 12:00:38 IST")
print(ggplot(df, aes(resolutiondate, age, size = counts, color = factor(isbreached))) +
geom_point(alpha = 0.4) +
geom_point(shape …Run Code Online (Sandbox Code Playgroud) 这是一个愚蠢的事情data.frame:
df <- read.table(textConnection(
"pole medal bag x y
north gold paper 0.852 0.423
north gold plastic 0.277 0.055
north silver paper 0.257 0.211
north silver plastic 0.457 0.614
north bronze paper 0.825 0.299
north bronze plastic 0.672 0.126
south gold paper 0.482 0.764
south gold plastic 0.603 0.869
south silver paper 0.327 0.451
south silver plastic 0.147 0.672
south bronze paper 0.140 0.466
south bronze plastic 0.833 0.325
"), header = TRUE)
Run Code Online (Sandbox Code Playgroud)
我知道如何以一种使用颜色和形状来表示两个因子属性的方式绘制这些数据的散点图。例如:
library(ggplot2)
ggplot(data = df, …Run Code Online (Sandbox Code Playgroud)