在双向网络图中为顶点标签使用不同的字体(Rstudio)

时间:2019-05-27 20:24:55

标签: r fonts label igraph

我想为R中的双向网络图中的顶点标签使用不同的字体。第一列是一个人的名字,第二列是该人所隶属的组织(可能有双重隶属关系)。

这是数据示例

    mBillingClient = BillingClient.newBuilder(this).enablePendingPurchases().setListener(this).build();
    mBillingClient.startConnection(new BillingClientStateListener() {
        @Override
        public void onBillingSetupFinished(BillingResult billingResult) {
            if (billingResult.getResponseCode() == OK) {
                    final Purchase.PurchasesResult purchasesResult = mBillingClient.queryPurchases(BillingClient.SkuType.INAPP);
                    if (purchasesResult.getResponseCode() == OK) {

                        final List<Purchase> purchases = purchasesResult.getPurchasesList();

                        for (final Purchase purchase : purchases) {
                        }
                    }
            }
        }
        @Override
        public void onBillingServiceDisconnected() {
            CommonUtils.showToast(mActivity, "disconnected");
        }
    });


    mUnlockPremiumButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

                final List<String> skuList = new ArrayList<> ();
                skuList.add(getString(R.string.inapp_premium_product_id));

                final SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder()
                    .setSkusList(skuList)
                    .setType(BillingClient.SkuType.INAPP);

                mBillingClient.querySkuDetailsAsync(params.build(),
                        new SkuDetailsResponseListener() {
                            @Override
                            public void onSkuDetailsResponse(BillingResult billingResult, List<SkuDetails> skuDetailsList) {

                                for (SkuDetails skuDetails : skuDetailsList) {
                                    if (getString(R.string.inapp_premium_product_id).equals(skuDetails.getSku())) {

                                        final BillingFlowParams flowParams = BillingFlowParams.newBuilder()
                                                .setSkuDetails(skuDetails)
                                                .build();

                                        final BillingResult result = mBillingClient.launchBillingFlow(mActivity, flowParams);

                                        if (result.getResponseCode() == ITEM_ALREADY_OWNED)
                                        {
                                            CommonUtils.showToast(mActivity, getString(R.string.alert_purchased));
                                        }
                                        else if (result.getResponseCode() != OK)
                                        {
                                            //always returns a getResponseCode of -1 (service disconnected)
                                        }
                                    }
                                }
                            }
                        });
        }
    });


我为绘图中识别出的数据分配了两种字体样式(无特殊样式)。但是,发生以下错误,我不知道该如何解决:

# R version 3.5.1 (2018-07-02) -- "Feather Spray"
# igraph 1.2.4

set.seed(7)

# bipartite network data
nodes <- read.csv("example.csv", header = TRUE, sep =";")
> nodes
   Person Organisation
1    John          SPD
2   Maria          SPD
3    John          CDU
4    Karl          CDU
5    Maik       Greens
6    Lisa         Left
7  Holger          SPD
8    Nico          CDU
9   Peter       Greens
10 Astrid          SPD
11   Theo         Left
12   Rita       Greens
13   Eric          FDP
14 Walter          CDU
15  Hilda          FDP
16  Boris          CDU
17   Olga          FDP
18   Nina         Left
19  Doris          CDU
20    Udo          SPD
summary(nodes)

library(igraph)

# different fonts and node shapes
shape <- c("circle", "square")
let <- c("Times", "Helvetica")

# creating graph (g)
g <- graph.data.frame(nodes, directed = FALSE)

# creating bipartite network
V(g)$type <- FALSE
V(g)$type[V(g)$name %in% nodes[, 1]] <- TRUE


plot(g, layout= layout_with_kk,
     vertex.shape= shape[as.numeric(V(g)$type) + 1],
     vertex.label.family= let[as.numeric(V(g)$type)+1]
)


我在这里找不到任何相关问题。
谢谢您的帮助和建议!

1 个答案:

答案 0 :(得分:1)

如果我只是运行您的代码,则会收到类似的错误消息,但是您可以通过在plot语句之前 包含这些语句来解决此问题。

windowsFonts("Times" = windowsFont("Times"))
windowsFonts("Helvetica" = windowsFont("Helvetica"))

当我包含这些语句时,没有收到错误消息,并且不同的节点类型以不同的字体显示。

Graph with multiple fonts in vertex labels