问题描述
我想在每个方面添加一个y轴。 facet_wrap(scales="free_y")
不执行我想要的操作,因为switch=y
移动了两个变量,而我只想移动一个。
- 有可能对此做些什么吗?
- 您是否知道是否还有另一种方法可以像
scales="free_y"
一样在每个构面上获取轴?。
谢谢您的时间。
#code for figure
ggplot(df,aes(factor(Year),Value,colour=Model,group=Model))+
geom_line(size=0.6)+
scale_colour_manual(values = c("Black","blue","darkgreen","red"))+
#scale_colour_manual(values = c("Black","#00539CFF","#006B38FF","#E94B3CFF"))+
scale_x_discrete(labels=c(1981,2005,2026,2050,2075,2100),breaks=factor(c(1981,2100)),expand = c(0.04,0.04))+
facet_grid(Variable~Location,scales = "free_y",switch = "y",# flip the facet labels along the y axis from the right side to the left
labeller = as_labeller(c(CDD = "CDD (Days)",CWD="CWD (Days)",R20="R20 (Days)",R50= "R50 (Days)",R95P="R95P (mm)",R99P="R99p (mm)",RX5DAY="RX5DAY (mm)",SDII="SDII (mm/day)",Bimodal="Bimodal",Unimodal="Unimodal")))+
labs(x="Year",y=element_blank(),colour=element_blank())+
guides(colour = guide_legend(override.aes = list(size = 2)))+
theme_bw(base_size = 15)+
theme(strip.background = element_blank(),# remove the background
strip.placement = "outside",legend.position = "bottom",legend.text = element_text(size = 15),axis.text = element_text(colour="black"))#,panel.spacing.x = unit(-0.90,"lines"),panel.spacing.y = unit(-0.80,"lines"))```
df<-structure(list(Year = c(2091,2091,2092,2093,2094,2095,2096,2097,2098,2099,2100,Variable = c("CDD","CDD","CDD"),Location = c("Unimodal","Unimodal","Bimodal","Bimodal"),Model = c("RCP2.6","RCP4.5","RCP8.5","RCP2.6","RCP8.5"),Value = c(188.47,184.03,199.62,172.65,204.21,186.82,179.75,196.57,198.9,185.33,193.11,197.07,174.92,200.37,210.65,176.48,200.01,203.91,170.33,200.67,192.44,164.03,200.35,188.92,169,208.69,196.54,183.62,203.8,201.36,135.92,141.75,145.53,111.85,145.43,160.49,127.08,144.34,155.95,127.36,154.24,155.37,127.92,135.34,155.45,139.08,146.16,160.27,129.21,151.82,145.07,108.86,161.75,146.93,134.71,155.76,157.29,117.42,155.58,150.69)),row.names = c(NA,-60L),class = c("tbl_df","tbl","data.frame"))
解决方法
也许这就是您要寻找的。在每个面上获得y轴的一种方法是利用拼凑而成,即为网格的每一列绘制单独的图并将这些图粘在一起。缺点之一:两个x轴都被标记:
import openpyxl
import io
# The bytes object (Something like b'PK\x03\x04\x14\x00\x06\x00\x08\x00\x00...)
file = part.get_payload(decode=True)
xlsx = io.BytesIO(file)
wb = openpyxl.load_workbook(xlsx)
ws = wb['Sheet1']
for cells in ws.iter_rows():
print([cell.value for cell in cells])