blob: 1309f3b5f40a8b70e32bd8ef383a0bd1704edf62 [file] [log] [blame]
Marc Kupietz12a9fe82020-06-16 14:27:57 +02001#!/usr/bin/env python3
2import rpy2.robjects.packages as packages
3import rpy2.robjects.pandas2ri as pandas2ri
4import plotly.express as px
5pandas2ri.activate()
6
7QUERY = "Hello World"
8YEARS = range(2010, 2019)
9COUNTRIES = ["DE", "CH"]
10
11RKorAPClient = packages.importr('RKorAPClient')
12kcon = RKorAPClient.KorAPConnection(verbose=True)
13
14vcs = ["textType=/Zeit.*/ & pubPlaceKey=" + c + " & pubDate in " + str(y) for c in COUNTRIES for y in YEARS]
15df = RKorAPClient.ipm(RKorAPClient.frequencyQuery(kcon, QUERY, vcs))
16df['Year'] = [y for c in COUNTRIES for y in YEARS]
17df['Country'] = [c for c in COUNTRIES for y in YEARS]
18
19fig = px.line(df, title=QUERY, x="Year", y="ipm", color="Country",
20 error_y="conf.high", error_y_minus="conf.low")
21fig.show()