问题描述
我想在ggplot中将size
,linetype
,color
等更改为一行。
这是一个最小的可重现示例:
library(tidyverse)
# Data in wide format
df_wide <- data.frame(
Horizons = seq(1,10,1),Country1 = c(2.5,2.3,2.2,2.1,2.0,1.7,1.8,1.6),Country2 = c(3.5,3.3,3.2,3.1,3.0,3.7,3.8,3.6),Country3 = c(1.5,1.3,1.2,1.1,1.0,0.7,0.8,0.6)
)
# Convert to long format
df_long <- df_wide %>%
gather(key = "variable",value = "value",-Horizons)
# Plot the lines
plotstov <- ggplot(df_long,aes(x = Horizons,y = value)) +
geom_line(aes(colour = variable,group = variable))+
theme_bw()
如何更改size
中的linetype
,color
,Country1
,而不必绘制每条线
分别为geom_line(aes( y = Country1...)) + geom_line(aes(y = Country2...))
,因此突出显示Country1
的行?
非常感谢!
解决方法
不是每行,但您只能分别绘制'Country1'
:
library(ggplot2)
ggplot(subset(df_long,variable != 'Country1'),aes(x = Horizons,y = value)) +
geom_line(aes(colour = variable,group = variable)) +
geom_line(data = subset(df_long,variable == 'Country1'),size = 3,linetype = 'dashed',color = 'blue') +
theme_bw()
,
一种实现此目的的方法是为code1
,color
等使用命名向量,然后可以在size
内部使用这些向量来设置所需的值。 / p>
scale_xxxx_manual
在this duplicate之后是这个问题的另一个答案。
它使用一个简单的技巧,通过将突出显示的变量与目标值进行比较来告诉突出显示的变量。这种二分法将其变为逻辑you can use a .dat file with doopl to read / write data with OPL from python:
from doopl.factory import *
# Create an OPL model from a .mod file
with create_opl_model(model="zootupleset.mod",data="zootupleset.dat") as opl:
# Generate the problem and solve it.
opl.run()
# Get the names of post processing tables
print("Table names are: "+ str(opl.output_table_names))
# Get all the post processing tables as dataframes.
for name,table in iteritems(opl.report):
print("Table : " + name)
for t in table.itertuples(index=False):
print(t)
# nicer display
for t in table.itertuples(index=False):
print(t[0]," buses ",t[1],"seats")
值。
params from SheetRead(s,"params!A2");
buses from SheetRead(s,"buses!A2:B3");
results to SheetWrite(s,"buses!E2:F3");
为了使标题和文本正确,现在需要特别注意图例。
FALSE/TRUE