我从excel取得数据并作图。第一列是日期,下两列是不同指数的价格。 我设法绘制它们,但是它们在单独的图形上。我需要它们以一个y轴(日期)和两个x轴相对于彼此绘制。
此外,我不知道如何使一条虚线和另一条虚线标记。
#old repex data from original question that has been edited above
library(tidyverse)
#create example dfs
df1 = data.frame(site = c(rep("s1",5), rep("s2",5)),grp = c("a1","a.","a.",rep("b",4),"b2","b-","bq"), measure = rnorm(10))
df2 = data.frame(site = c(rep("s1",10), rep("s2",16)), grp = c(rep("as", 3), "b2",rep("a",22)), measure2 = rnorm(26))
df3 = data.frame(site = c(rep("s1",3), rep("s2",6)),grp = c(rep("b-",3),rep("bq",2),"a", rep("a.", 3)), measure3 = 1:9)
site_list = list("s1","s2")
bad_values = list(c("a1","a.","as", "b2", "b-", "bq"),
c("a1","a.","as","b", "b2", "b-", "bq"))
good_values = list(c("a", "a1","a2","b","b1","b2"),
c("f","f1","f2","g","g","g1","g2"))
我希望比特币和S%P的价格位于y轴上,日期位于x轴上。
答案 0 :(得分:1)
我正在使用seaborn
中的iris DataFrame提供示例答案。您可以根据需要对其进行修改。您需要一个x轴和两个y轴。
import seaborn as sns
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
iris = sns.load_dataset("iris")
iris.plot(x='sepal_length', y='sepal_width', linestyle=':', ax=ax)
iris.plot(x='petal_length', y='petal_width', marker='d',
linestyle='None', secondary_y=True, ax=ax)