如何用gtrendsR获取Google Trends国家级别interest_by_country数据
Hey there! Let's break down your two gtrendsR questions with clear examples and explanations:
1. How to View interest_by_country Data
When you run gtrends(), it returns a list object with several components—one of which is exactly interest_by_country, a data frame containing country-level relative interest scores for your keywords.
Here's how to access and inspect it:
library(gtrendsR) # Replace with your actual keywords and desired broad geo (e.g., "world" for global data) trend_results <- gtrends( keyword = c("keyword1", "keyword2"), geo = "world" ) # Print the country-level interest data to console print(trend_results$interest_by_country) # For a more readable table in RStudio, use View() View(trend_results$interest_by_country)
Note: interest_by_country only populates when your geo parameter is a broad region (like "world", "EU") that includes multiple countries. If you set geo to a single country (e.g., "TR"), this component will be empty.
2. Getting National-Level Interest Data for Turkey (geo = "TR")
First, a quick clarification: Google Trends doesn't provide absolute "click numbers"—all values are relative interest scores (0-100, representing the popularity of a keyword relative to the highest point in the selected region and time period).
If you're seeing only city-level data when setting geo = "TR", that's because the interest_by_region component returns sub-national regions (cities/provinces) for a single country. To get national-level data, use one of these approaches:
Option 1: National-level time series trend
The interest_over_time component of the gtrends() result gives you the overall relative interest for the entire country over time. This is the national-level trend you're looking for:
tr_trend <- gtrends( keyword = c("your_keyword1", "your_keyword2"), geo = "TR" ) # Inspect the national-level time series data head(tr_trend$interest_over_time)
Option 2: Turkey's national score compared to other countries
If you want to see Turkey's national interest score alongside other countries, set geo = "world" and filter the interest_by_country data:
tr_world_trend <- gtrends( keyword = "your_keyword", geo = "world" ) # Filter to get only Turkey's national data turkey_national_data <- subset( tr_world_trend$interest_by_country, location == "Turkey" ) print(turkey_national_data)
内容的提问来源于stack exchange,提问作者omzeybek

