相关疑难解决方法(0)

如何在ggplot中更改线宽?

数据链接:使用 的数据

我的代码:

ccfsisims <- read.csv(file = "F:/Purdue University/RA_Position/PhD_ResearchandDissert/PhD_Draft/GTAP-CGE/GTAP_NewAggDatabase/NewFiles/GTAP_ConsIndex.csv", header=TRUE, sep=",", na.string="NA", dec=".", strip.white=TRUE)
ccfsirsts <- as.data.frame(ccfsisims)
ccfsirsts[6:24] <- sapply(ccfsirsts[6:24],as.numeric)
ccfsirsts <- droplevels(ccfsirsts)
ccfsirsts <- transform(ccfsirsts,sres=factor(sres,levels=unique(sres)))

library(ggplot2)

#------------------------------------------------------------------------------------------
#### Plot of food security index for Morocco and Turkey by sector
#------------------------------------------------------------------------------------------

#_Code_Begin...

datamortur <- melt(ccfsirsts[ccfsirsts$region %in% c("TUR","MAR"), ]) # Selecting regions of interest
datamortur1 <- datamortur[datamortur$variable %in% c("pFSI2"), ] # Selecting the food security index of interest
datamortur2 <- datamortur1[datamortur1$sector %in% c("wht","gro","VegtFrut","osd","OthCrop","VegtOil","XPrFood"), ] # Selecting food sectors of interest
datamortur3 …
Run Code Online (Sandbox Code Playgroud)

r ggplot2 line-plot

112
推荐指数
5
解决办法
25万
查看次数

更改ggplot中的线宽,而不是大小

我看到几篇关于改变 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)

r ggplot2

12
推荐指数
1
解决办法
787
查看次数

标签 统计

ggplot2 ×2

r ×2

line-plot ×1