Skip to content

Commit

Permalink
feat(open-alex): Create graph about the share of retractactions by co…
Browse files Browse the repository at this point in the history
…untry
  • Loading branch information
annelhote committed Feb 23, 2024
1 parent 0245053 commit e5f8e71
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 38 deletions.
48 changes: 48 additions & 0 deletions client/src/pages/open-alex/charts/retracted-by-country-share.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { useQuery } from '@tanstack/react-query';
import Highcharts from 'highcharts';
import HighchartsReact from 'highcharts-react-official';

export default function RetractedByCountryShare() {
const { data: data1, isLoading: isLoading1 } = useQuery({
queryKey: ['GetOpeAlexRetractions'],
queryFn: () => fetch('https://api.openalex.org/works?page=1&filter=is_retracted:true&group_by=authorships.countries').then((response) => response.json())
});

const { data: data2, isLoading: isLoading2 } = useQuery({
queryKey: ['GetOpeAlexPublications'],
queryFn: () => fetch('https://api.openalex.org/works?page=1&group_by=authorships.countries').then((response) => response.json())
});

if (isLoading1 || isLoading2) {
return <div>Loading...</div>;
}

const series = (data1?.group_by?.slice(0, 20) ?? []).map((country) => {
const total = data2.group_by.find((item) => item.key === country.key).count;
return ({
color: country.key === 'FR' ? '#cc0000' : '#808080',
name: country.key_display_name,
total,
// y: country.count,
y: country.count / total * 10000,
})
}).sort((a, b) => b.y - a.y);
const categories = series.map((country) => country.name);

const options = {
chart: { type: 'column' },
legend: { enabled: false },
title: { text: 'Part of retracted publications by country (top 20)' },
xAxis: { categories, title: { text: 'Country' } },
yAxis: { title: { text: 'Part of retracted publications (‱)' } },
series: [{ data: series }],
plotOptions: { column: { dataLabels: { enabled: true, format: '{y:.2f} %' } } }
};

return (
<HighchartsReact
highcharts={Highcharts}
options={options}
/>
);
}
38 changes: 38 additions & 0 deletions client/src/pages/open-alex/charts/retracted-by-country.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { useQuery } from '@tanstack/react-query';
import Highcharts from 'highcharts';
import HighchartsReact from 'highcharts-react-official';

export default function RetractedByCountry() {
const { data, isLoading } = useQuery({
queryKey: ['GetOpeAlexRetractions'],
queryFn: () => fetch('https://api.openalex.org/works?page=1&filter=is_retracted:true&group_by=authorships.countries').then((response) => response.json())
});

if (isLoading) {
return <div>Loading...</div>;
}

const series = (data?.group_by?.slice(0, 20) ?? []).map((country) => ({
color: country.key === 'FR' ? '#cc0000' : '#808080',
name: country.key_display_name,
y: country.count,
}));
const categories = series.map((country) => country.name);

const options = {
chart: { type: 'column' },
legend: { enabled: false },
title: { text: 'Number of retracted publications by country (top 20)' },
xAxis: { categories, title: { text: 'Country' } },
yAxis: { title: { text: 'Number of retracted publications' } },
series: [{ data: series }],
plotOptions: { column: { dataLabels: { enabled: true } } }
};

return (
<HighchartsReact
highcharts={Highcharts}
options={options}
/>
);
}
45 changes: 7 additions & 38 deletions client/src/pages/open-alex/index.tsx
Original file line number Diff line number Diff line change
@@ -1,42 +1,11 @@
import { useQuery } from '@tanstack/react-query';
import Highcharts from 'highcharts';
import HighchartsReact from 'highcharts-react-official';
import RetractedByCountry from './charts/retracted-by-country';
import RetractedByCountryShare from './charts/retracted-by-country-share'

export default function Welcome() {
const GetHorizon2020Participation = () => {
const url = 'https://api.openalex.org/works?page=1&filter=is_retracted:true&group_by=authorships.countries';
return fetch(url).then((response) => response.json());
}

const { data, isLoading } = useQuery({
queryKey: ['GetOpeAlexRetractions'],
queryFn: () => GetHorizon2020Participation()
});

if (isLoading) {
return <div>Loading...</div>;
}

const series = (data?.group_by?.slice(0, 20) ?? []).map((country) => ({
color: country.key === 'FR' ? '#cc0000' : '#808080',
name: country.key_display_name,
y: country.count,
}));
const categories = series.map((country) => country.name);

const options = {
chart: { type: 'column' },
legend: { enabled: false },
title: { text: 'Number of retracted publications by country (top 20)' },
xAxis: { categories, title: { text: 'Country' } },
yAxis: { title: { text: 'Number of publications' } },
series: [{ data: series }],
};

return (
<HighchartsReact
highcharts={Highcharts}
options={options}
/>
)
<>
<RetractedByCountry />
<RetractedByCountryShare />
</>
);
}

0 comments on commit e5f8e71

Please sign in to comment.