我有以下数据:
import pandas as pd
import numpy as np
# Generate dummy data.
a = np.random.random(75)
b = np.random.random(75) - 0.6
c = np.random.random(75) + 0.75
# Collate into a DataFrame
df = pd.DataFrame({'a': a, 'b': b, 'c': c})
df.columns = [list(['WT', 'MUT', 'WTxMUT']), list(['Parent', 'Parent', 'Offspring'])]
df.columns.names = ['Genotype', 'Status']
df_melt = pd.melt(df)
Run Code Online (Sandbox Code Playgroud)
我使用以下代码在seaborn中绘制它:
import seaborn as sb
sb.swarmplot(data = df_melt, x = "Status", y = "value", hue = "Genotype")
Run Code Online (Sandbox Code Playgroud)

如何获得每个组的 x 跨度?例如,父组的群图水平跨度范围是多少?
我想使用ggridges.
# toy example
ggplot(iris, aes(x=Sepal.Length, y=Species, fill=..x..)) +
geom_density_ridges_gradient(jittered_points = FALSE, quantile_lines =
FALSE, quantiles = 2, scale=0.9, color='white') +
scale_y_discrete(expand = c(0.01, 0)) +
theme_ridges(grid = FALSE, center = TRUE)
Run Code Online (Sandbox Code Playgroud)
我想在 7 处为 virginica 添加一条垂直线,为 versicolor 添加 4 条,为 setosa 添加 5 条垂直线。关于如何做到这一点的任何想法?
为什么情节的顶部被切断了,我该如何解决这个问题?我增加了利润率,但没有任何区别。
查看 1854 年的曲线,位于左侧驼峰的最顶端。看起来驼峰顶部的线条更细。对我来说,将大小更改为 0.8 无济于事。
这是生成此示例所需的代码:
library(tidyverse)
library(ggridges)
t2 <- structure(list(Date = c("1853-01", "1853-02", "1853-03", "1853-04",
"1853-05", "1853-06", "1853-07", "1853-08", "1853-09", "1853-10",
"1853-11", "1853-12", "1854-01", "1854-02", "1854-03", "1854-04",
"1854-05", "1854-06", "1854-07", "1854-08", "1854-09", "1854-10",
"1854-11", "1854-12"), t = c(-5.6, -5.3, -1.5, 4.9, 9.8, 17.9,
18.5, 19.9, 14.8, 6.2, 3.1, -4.3, -5.9, -7, -1.3, 4.1, 10, 16.8,
22, 20, 16.1, 10.1, 1.8, -5.6), year = c("1853", "1853", "1853",
"1853", "1853", "1853", "1853", "1853", "1853", "1853", "1853",
"1853", "1854", "1854", "1854", …Run Code Online (Sandbox Code Playgroud) 我从这个网站下载了 otf 文件。我的 IT 部门安装了“Font Awesome 5 Free Regular”,我使用了
library(extrafont)
font_import()
loadfonts(device = "win")
Run Code Online (Sandbox Code Playgroud)
我可以看到 Font Awesome 注册了“Font Awesome 5 Free Regular”。当我尝试将它与此测试代码一起使用时:
waffle(c(50, 30, 15, 5), rows = 5, use_glyph = "music", glyph_size = 6)
Run Code Online (Sandbox Code Playgroud)
我得到
Error: FontAwesome not found. Install via: https://github.com/FortAwesome/Font-Awesome/tree/master/fonts
Run Code Online (Sandbox Code Playgroud)
但该链接不会去任何地方。
我想使用 Font Awesome(或一个很好的替代方案)来制作有趣的华夫饼图。我是否错误地加载了字体?我缺少更好的选择吗?我一直在使用这篇文章作为指导。我还在stackoverflow 上阅读了一个相关的问题,但它没有帮助。我已经多次重新启动 Rstudio(和计算机),但没有成功。
更新
还是行不通。我已经删除并重新安装了 waffle 和 emojifont 包。我仍然收到错误代码:“错误:未找到 FontAwesome。通过以下方式安装:https : //github.com/FortAwesome/Font-Awesome/tree/master/fonts ”
我正在尝试为ggplot2 中geom_segment的geom_density_ridges绘图添加方法。
library(dplyr)
library(ggplot2)
library(ggridges)
Fig1 <- ggplot(Figure3Data, aes(x = `hairchange`, y = `EffortGroup`)) +
geom_density_ridges_gradient(aes(fill = ..x..), scale = 0.9, size = 1)
ingredients <- ggplot_build(Fig1) %>% purrr::pluck("data", 1)
density_lines <- ingredients %>%
group_by(group) %>% filter(density == mean(density)) %>% ungroup()
p <- ggplot(Figure3Data, aes(x = `hairchange`, y = `EffortGroup`)) +
geom_density_ridges_gradient(aes(fill = ..x..), scale = 0.9, size = 1) +
scale_fill_gradientn( colours = c("#0000FF", "#FFFFFF", "#FF0000"),name =
NULL, limits=c(-2,2))+ coord_flip() +
theme_ridges(font_size = 20, grid=TRUE, …Run Code Online (Sandbox Code Playgroud) 我一直在玩这个waffle包,并试图让它与gganimate.
作为mpg示例,我创建了华夫饼图来显示每个模型的数量class。然后,我想使用 gganimate 依次显示每个制造商按类别划分的模型图表。我可以用来facet_wrap()同时显示所有制造商的图表,但希望能够循环浏览它们。
当我尝试将 gganimate 应用于华夫饼图时,出现错误:
mapply(FUN = f, ..., SIMPLIFY = FALSE) 中的错误:零长度输入不能与非零长度输入混合
我不确定是否waffle与 不兼容gganimate,或者我是否做错了什么。
这是代码:
library(tidyverse)
library(waffle)
library(gganimate)
data("mpg")
d <- mpg
d$class <- as.factor(d$class)
d$manufacturer <- as.factor(d$manufacturer)
plot <- d %>% count(manufacturer, class) %>%
ggplot(aes(fill = class, values = n)) +
geom_waffle(color = "white",
size = .75,
n_rows = 4) +
ggthemes::scale_fill_tableau(name = NULL) +
coord_equal() +
theme_minimal() +
theme(panel.grid = element_blank(), …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试使用 Atari 模块进行gym/openai。我已成功安装依赖项。
Patricks-MacBook-Pro:~ patrickmaynard$ python3.6 -m pip install gym[atari]
Requirement already satisfied: gym[atari] in /usr/local/lib/python3.6/site-packages (0.10.5)
Requirement already satisfied: six in /usr/local/lib/python3.6/site-packages (from gym[atari]) (1.11.0)
Requirement already satisfied: pyglet>=1.2.0 in /usr/local/lib/python3.6/site-packages (from gym[atari]) (1.3.2)
Requirement already satisfied: requests>=2.0 in /usr/local/lib/python3.6/site-packages (from gym[atari]) (2.18.4)
Requirement already satisfied: numpy>=1.10.4 in /usr/local/lib/python3.6/site-packages (from gym[atari]) (1.14.3)
Requirement already satisfied: Pillow; extra == "atari" in /usr/local/lib/python3.6/site-packages (from gym[atari]) (5.1.0)
Requirement already satisfied: PyOpenGL; extra == "atari" in /usr/local/lib/python3.6/site-packages (from gym[atari]) (3.1.0)
Requirement already satisfied: …Run Code Online (Sandbox Code Playgroud) 我试图让我的群图更容易以黑白方式阅读,并且对于色盲的人来说,通过让色调不仅影响颜色,还影响标记的另一个几何方面。
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="whitegrid")
tips = sns.load_dataset("tips")
fig, ax = plt.subplots(1,1)
ax = sns.swarmplot(x="day", y="total_bill", hue="sex",data=tips,size=8,ax=ax)
plt.show()
Run Code Online (Sandbox Code Playgroud)
我有一个数据集,作为 CSV 格式的要点上传到这里。它是 YouGov 文章“‘好’有多好?”中提供的 PDF 的提取形式。. 被要求用 0(非常负面)和 10(非常正面)之间的分数对单词(例如“完美”、“糟糕”)进行评分的人。要点正好包含该数据,即对于每个单词(列:单词),它为从 0 到 10(列:类别)的每个排名存储投票数(列:总计)。
我通常会尝试使用 matplotlib 和 Python 来可视化数据,因为我缺乏 R 方面的知识,但似乎 ggridges 可以创建比我使用 Python 所做的更好的绘图。
使用:
library(ggplot2)
library(ggridges)
YouGov <- read_csv("https://gist.githubusercontent.com/camminady/2e3aeab04fc3f5d3023ffc17860f0ba4/raw/97161888935c52407b0a377ebc932cc0c1490069/poll.csv")
ggplot(YouGov, aes(x=Category, y=Word, height = Total, group = Word, fill=Word)) +
geom_density_ridges(stat = "identity", scale = 3)
Run Code Online (Sandbox Code Playgroud)
忽略我必须调整美学的事实,我很难做到三件事:
我试图调整来自这个来源的建议,但最终失败了,因为我的数据似乎格式错误:我已经有了每个类别的汇总投票数,而不是单一的投票实例。
我希望最终得到一个更接近这个情节的结果,它满足标准 3(来源):

我正在尝试全屏制作传单地图,并在地图顶部添加过滤器控件。但是,当我尝试这样做时,我的过滤器控件(绝对面板)在运行时隐藏在传单输出后面。
我希望地图是全屏的,当我这样做时,它会隐藏在地图后面。
如何使地图位于绝对面板后面?任何帮助表示赞赏。
谢谢
下面是界面代码:
fluidPage(style="padding-top: 10px;",
h1("Locations"),
absolutePanel(
top = 60, left = "auto", right = 20, bottom = "auto",
width = 330, height = "auto",draggable = TRUE,
wellPanel(
selectInput("Suburb", "Select one Suburb:",choices = c("Select one Suburb" = "All", as.character(mydata$SuburbTown))),
uiOutput("secondselection")
),
style = "opacity: 0.65"
),
leafletOutput("leafl", height = "800px")
)
Run Code Online (Sandbox Code Playgroud) r ×7
ggplot2 ×5
ggridges ×3
python ×2
seaborn ×2
swarmplot ×2
waffle-chart ×2
animation ×1
css ×1
density-plot ×1
font-awesome ×1
gganimate ×1
javascript ×1
matplotlib ×1
openai-gym ×1
pip ×1
plot ×1
python-3.x ×1
shiny ×1