我看到几篇关于改变 ggplot中线宽的帖子.答案虽然对OP有效且有效,但会改变线条大小.也就是说,ggplot似乎将线条视为一系列单位,并且尺寸增加了每个单元的长度和宽度,使得其他调整更粗糙.
我希望有一种方法可以使线条更宽(更厚)而不会影响长度,反过来又会影响破折号.
我从https://cran.r-project.org/web/packages/ggplot2/vignettes/ggplot2-specs.html借用了一些代码来说明我的意思:
library(ggplot2)
#A simple plot with manually set dashes.
#The first numeral is units of dash length, the second units in the gap in hexadecimal.
lty <- c("11", "18", "1f", "81", "88", "8f", "f1", "f8", "ff")
linetypes <- data.frame(y = seq_along(lty), lty = lty)
ggplot(linetypes, aes(0, y)) +
geom_segment(aes(xend = 5, yend = y, linetype = lty)) +
scale_linetype_identity() +
geom_text(aes(label = lty), hjust = 0, nudge_y = 0.2) + …
Run Code Online (Sandbox Code Playgroud) 我在这个链接中有一个数据框 ,我有以下代码:
load("Fish11a.rda")
df=Fish11a
df=data.frame(Time=as.factor(df[,6]),RoiID=df[,3],Diameter=df[,8])
df$Time.hours=rep(1:10,each=104*max(df$RoiID),len=nrow(df))
df$Time <- factor(df$Time, levels=rev(levels(df$Time)))
df1=split(df,df$Time.hours)
br=lapply(split(df,df$Time.hours), function(x) {
br=data.frame(x[c(1,round(nrow(x)*(1:4)/4)),])
br$Min=c(0,15,30,45,60)
return(br)
})
hle1=function(dfr,br,tenplot) {
require(ggplot2)
require(gtable)
library(grid)
#start plot
g=ggplot(data=dfr, aes(x=factor(RoiID), y=Time, fill = Diameter)) +
theme_minimal() + coord_fixed(ratio=1) +
geom_tile(colour = NA, width = 1.5, height = 1)+
scale_fill_gradient(low="black",high="white")+
theme(axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank())+
scale_x_discrete(expand = c(0,0))+
scale_y_discrete(name="Time (min)",
expand = c(0,0),
breaks=br$Time,labels=br$Min)+
theme(axis.ticks.length = unit(0, "lines"))+
ggtitle(tenplot)+
theme(plot.title = element_text(size = 10, face = "bold"))
# calculate segment coordinates
segs <- c(.39, …
Run Code Online (Sandbox Code Playgroud)