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