我正在尝试使用来自此站点的 College Scorecard 数据在 MatPlotLib 中创建一个 100% 堆积条形图。
有 38 列是: [在此处插入研究领域] 授予学位的百分比 这解释了为什么有 38 个领域!
我有一个学校的子集,我想为其做这个堆积图。
我尝试按照此处的说明进行操作。是的。这是很长的代码,但我想按本书播放。(加上我在这个博客上一直很幸运)这些数据随这些 PCIP(按研究领域授予的学位百分比)提供,以百分比形式出现,因此我不必遵循 Chris 的计算,因为它们已经完成.
运行代码时出现错误:
bar_width = 1
bar_l = [i for i in range(len(df['PCIP01']))]
tick_pos = [i+(bar_width/2) for i in bar_l]
# Create a figure with a single subplot
f, ax = plt.subplots(1, figsize=(10,5))
ax.bar(bar_l,
degrees.PCIP01,
label='PCIP01',
alpha=0.9,
color='#2D014B',
width=bar_width
)
ax.bar(bar_l,
PCIP04,
label='PCIP04',
alpha=0.9,
color='#28024E',
width=bar_width
)
Run Code Online (Sandbox Code Playgroud)
[对所有剩余的 36 个字段依此类推
# Set the ticks to be School …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Plotly 中制作一个 3x3 子图的网格。我正在尝试获取每个子图的标题和顶部的主标题,但我似乎无法让它工作。我看到了这个很棒的 Python站点,但我似乎找不到 R 的等效站点。
all <- subplot(graph1, graph2, graph3, graph4, graph5, graph6,
graph7, graph8, graph9, nrows = 3)
Run Code Online (Sandbox Code Playgroud)
这给了我想要的网格,但在子图上没有我想要的标题:
1. Graph 1
2. Graph 2
3. Graph 3
4. Graph 4
5. Graph 5
6. Graph 6
7. Graph 7
8. Graph 8
9. Graph 9
Run Code Online (Sandbox Code Playgroud)
并且默认的主标题是图表 9。
任何人都可以提供帮助吗?
几周前,这里有人帮助我极大地获得了Notable Names数据库中所有链接的列表。我能够运行此代码并获得以下输出
library(purrr)
library(rvest)
url_base <- "https://www.nndb.com/lists/494/000063305/"
## Gets A-Z links
all_surname_urls <- read_html(url_base) %>%
html_nodes(".newslink") %>%
html_attrs() %>%
map(pluck(1, 1))
all_ppl_urls <- map(
all_surname_urls,
function(x) read_html(x) %>%
html_nodes("a") %>%
html_attrs() %>%
map(pluck(1, 1))
) %>%
unlist()
all_ppl_urls <- setdiff(
all_ppl_urls[!duplicated(all_ppl_urls)],
c(all_surname_urls, "http://www.nndb.com/")
)
all_ppl_urls[1] %>%
read_html() %>%
html_nodes("p") %>%
html_text()
# [1] "AKA Lee William Aaker"
# [2] "Born: 25-Sep-1943Birthplace: Los Angeles, CA"
# [3] "Gender: MaleRace or Ethnicity: WhiteOccupation: Actor"
# [4] "Nationality: United StatesExecutive summary: The Adventures …Run Code Online (Sandbox Code Playgroud) 我有32K行地址,我必须找到长/纬度值.
我正在使用此处找到的代码.我非常感谢这个人创造它,但我有一个问题:
我想编辑它,以便如果循环遇到当前行地址的问题,它只是在Lat/Long字段中表示NA并移动到下一个.有谁知道如何实现这一目标?代码如下:
# Geocoding a csv column of "addresses" in R
#load ggmap
library(ggmap)
# Select the file from the file chooser
fileToLoad <- file.choose(new = TRUE)
# Read in the CSV data and store it in a variable
origAddress <- read.csv(fileToLoad, stringsAsFactors = FALSE)
# Initialize the data frame
geocoded <- data.frame(stringsAsFactors = FALSE)
# Loop through the addresses to get the latitude and longitude of each address and add it to the
# origAddress data …Run Code Online (Sandbox Code Playgroud)